Пример #1
0
    def load(f, model, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.modflow.mf.Modflow`) to
            which this package will be added.
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        swt : ModflowSwt object

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> swt = flopy.modflow.ModflowSwt.load('test.swt', m)

        """

        if model.verbose:
            sys.stdout.write('loading swt package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()

        # read dataset 1
        if model.verbose:
            sys.stdout.write('  loading swt dataset 1\n')
        t = line.strip().split()
        ipakcb, iswtoc, nsystm, ithk, ivoid, istpcs, icrcc = int(t[0]), int(t[1]), int(t[2]), int(t[3]), \
                                                             int(t[4]), int(t[5]), int(t[6])

        if ipakcb > 0:
            ipakcb = 53

        # read dataset 2
        lnwt = None
        if nsystm > 0:
            if model.verbose:
                sys.stdout.write('  loading swt dataset 2\n')
            lnwt = np.empty((nsystm), dtype=np.int)
            lnwt = read1d(f, lnwt) - 1

        # read dataset 3
        if model.verbose:
            sys.stdout.write('  loading swt dataset 3\n')
        line = f.readline()
        t = line.strip().split()
        iizcfl, izcfm, iglfl, iglfm, iestfl, \
        iestfm, ipcsfl, ipcsfm, istfl, istfm = int(t[0]), int(t[1]), int(t[2]), int(t[3]), int(t[4]), \
                                               int(t[5]), int(t[6]), int(t[7]), int(t[8]), int(t[9])

        # read dataset 4
        if model.verbose:
            sys.stdout.write('  loading swt dataset 4')
        gl0 = Util2d.load(f, model, (nrow, ncol), np.float32, 'gl0', ext_unit_dict)

        # read dataset 5
        if model.verbose:
            sys.stdout.write('  loading swt dataset 5')
        sgm = Util2d.load(f, model, (nrow, ncol), np.float32, 'sgm', ext_unit_dict)

        # read dataset 6
        if model.verbose:
            sys.stdout.write('  loading swt dataset 6')
        sgs = Util2d.load(f, model, (nrow, ncol), np.float32, 'sgs', ext_unit_dict)

        # read datasets 7 to 13
        thick = [0] * nsystm
        void = [0] * nsystm
        sub = [0] * nsystm
        if icrcc == 0:
            sse = None
            ssv = None
            cr = [0] * nsystm
            cc = [0] * nsystm
        else:
            sse = [0] * nsystm
            ssv = [0] * nsystm
            cr = None
            cc = None

        for k in range(nsystm):
            kk = lnwt[k] + 1
            # thick
            if model.verbose:
                sys.stdout.write('  loading swt dataset 7 for layer {}\n'.format(kk))
            t = Util2d.load(f, model, (nrow, ncol), np.float32, 'thick layer {}'.format(kk),
                            ext_unit_dict)
            thick[k] = t
            if icrcc != 0:
                # sse
                if model.verbose:
                    sys.stdout.write('  loading swt dataset 8 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'sse layer {}'.format(kk),
                                ext_unit_dict)
                sse[k] = t
                # ssv
                if model.verbose:
                    sys.stdout.write('  loading swt dataset 9 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'sse layer {}'.format(kk),
                                ext_unit_dict)
                ssv[k] = t
            else:
                # cr
                if model.verbose:
                    sys.stdout.write('  loading swt dataset 10 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'cr layer {}'.format(kk),
                                ext_unit_dict)
                cr[k] = t
                # cc
                if model.verbose:
                    sys.stdout.write('  loading swt dataset 11 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'cc layer {}'.format(kk),
                                ext_unit_dict)
                cc[k] = t
            # void
            if model.verbose:
                sys.stdout.write('  loading swt dataset 12 for layer {}\n'.format(kk))
            t = Util2d.load(f, model, (nrow, ncol), np.float32, 'void layer {}'.format(kk),
                            ext_unit_dict)
            void[k] = t
            # sub
            if model.verbose:
                sys.stdout.write('  loading swt dataset 13 for layer {}\n'.format(kk))
            t = Util2d.load(f, model, (nrow, ncol), np.float32, 'sub layer {}'.format(kk),
                            ext_unit_dict)
            sub[k] = t

        # dataset 14 and 15
        if istpcs != 0:
            pcsoff = [0] * nlay
            pcs = None
        else:
            pcsoff = None
            pcs = [0] * nlay
        for k in range(nlay):
            if istpcs != 0:
                if model.verbose:
                    sys.stdout.write('  loading swt dataset 14 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'pcsoff layer {}'.format(k + 1),
                                ext_unit_dict)
                pcsoff[k] = t
            else:
                if model.verbose:
                    sys.stdout.write('  loading swt dataset 15 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'pcs layer {}'.format(k + 1),
                                ext_unit_dict)
                pcs[k] = t

        ids16 = None
        ids17 = None
        if iswtoc > 0:
            # dataset 16
            if model.verbose:
                sys.stdout.write('  loading swt dataset 15 for layer {}\n'.format(kk))
            ids16 = np.empty(26, dtype=np.int)
            ids16 = read1d(f, ids16)
            for k in range(1, 26, 2):
                model.add_pop_key_list(ids16[k])
                ids16[k] = 2054  # all sub-wt data sent to unit 2054
            # dataset 17
            ids17 = [0] * iswtoc
            for k in range(iswtoc):
                if model.verbose:
                    sys.stdout.write('  loading swt dataset 17 for iswtoc {}\n'.format(k + 1))
                t = np.empty(30, dtype=np.int)
                t = read1d(f, t)
                t[0:4] -= 1
                ids17[k] = t

        # close file
        f.close()

        # create sub-wt instance
        swt = ModflowSwt(model, ipakcb=ipakcb, iswtoc=iswtoc, nsystm=nsystm, ithk=ithk, ivoid=ivoid, istpcs=istpcs,
                         icrcc=icrcc, lnwt=lnwt, izcfl=iizcfl, izcfm=izcfm, iglfl=iglfl, iglfm=iglfm, iestfl=iestfl,
                         iestfm=iestfm, ipcsfl=ipcsfl, ipcsfm=ipcsfm, istfl=istfl, istfm=istfm, gl0=gl0, sgm=sgm,
                         sgs=sgs, thick=thick, sse=sse, ssv=ssv, cr=cr, cc=cc, void=void, sub=sub, pcsoff=pcsoff,
                         pcs=pcs, ids16=ids16, ids17=ids17)
        # return sut-wt instance
        return swt
Пример #2
0
    def load(f, model, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.modflow.mf.Modflow`) to
            which this package will be added.
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        dis : ModflowDisU object
            ModflowDisU object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> disu = flopy.modflow.ModflowDisU.load('test.disu', m)

        """

        if model.verbose:
            sys.stdout.write('loading disu package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')

        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break

        # dataset 1
        if model.verbose:
            print('   loading NODES, NLAY, NJAG, IVSD, NPER, ITMUNI, LENUNI,'
                  ' IDSYMRD...')
        ll = line.strip().split()
        nodes = int(ll.pop(0))
        nlay = int(ll.pop(0))
        njag = int(ll.pop(0))
        ivsd = int(ll.pop(0))
        nper = int(ll.pop(0))
        itmuni = int(ll.pop(0))
        lenuni = int(ll.pop(0))
        idsymrd = int(ll.pop(0))
        if model.verbose:
            print('   NODES {}'.format(nodes))
            print('   NLAY {}'.format(nlay))
            print('   NJAG {}'.format(njag))
            print('   IVSD {}'.format(ivsd))
            print('   NPER {}'.format(nper))
            print('   ITMUNI {}'.format(itmuni))
            print('   LENUNI {}'.format(lenuni))
            print('   IDSYMRD {}'.format(idsymrd))

        # Calculate njags
        njags = (njag - nodes) / 2
        if model.verbose:
            print('   NJAGS calculated as {}'.format(njags))

        # dataset 2 -- laycbd
        if model.verbose:
            print('   loading LAYCBD...')
        laycbd = np.empty((nlay), np.int)
        laycbd = read1d(f, laycbd)
        if model.verbose:
            print('   LAYCBD {}'.format(laycbd))

        # dataset 3 -- nodelay
        if model.verbose:
            print('   loading NODELAY...')
        nodelay = Util2d.load(f, model, (1, nlay), np.int, 'nodelay',
                               ext_unit_dict)
        if model.verbose:
            print('   NODELAY {}'.format(nodelay))

        # dataset 4 -- top
        if model.verbose:
            print('   loading TOP...')
        top = [0] * nlay
        for k in range(nlay):
            tpk = Util2d.load(f, model, (1, nodelay[k]), np.float32, 'top',
                               ext_unit_dict)
            top[k] = tpk
        if model.verbose:
            for tpk in top:
                print('   TOP layer {}: {}'.format(k, tpk))

        # dataset 5 -- bot
        if model.verbose:
            print('   loading BOT...')
        bot = [0] * nlay
        for k in range(nlay):
            btk = Util2d.load(f, model, (1, nodelay[k]), np.float32, 'btk',
                               ext_unit_dict)
            bot[k] = btk
        if model.verbose:
            for btk in bot:
                print('   BOT layer {}: {}'.format(k, btk))

        # dataset 6 -- area
        if model.verbose:
            print('   loading AREA...')
        if ivsd == -1:
            area = Util2d.load(f, model, (1, nodelay[0]), np.float32, 'area',
                                   ext_unit_dict)
        else:
            area = [0] * nlay
            #area = np.empty((nodes), dtype=np.float32)
            #istart = 0
            for k in range(nlay):
                ak = Util2d.load(f, model, (1, nodelay[k]), np.float32, 'ak',
                                   ext_unit_dict)
                #area[istart : istart + nodelay[k]] = ak.array.reshape((nodelay[k]))
                #istart += nodelay[k]
                area[k] = ak
        if model.verbose:
            print('   AREA {}'.format(area))

        # dataset 7 -- iac
        if model.verbose:
            print('   loading IAC...')
        iac = Util2d.load(f, model, (1, nodes), np.int, 'iac',
                               ext_unit_dict)
        iac = iac.array.reshape((nodes))
        if model.verbose:
            print('   IAC {}'.format(iac))

        # dataset 8 -- ja
        if model.verbose:
            print('   loading JA...')
        ja = Util2d.load(f, model, (1, njag), np.int, 'ja',
                               ext_unit_dict)
        ja = ja.array.reshape((njag))
        if model.verbose:
            print('   JA {}'.format(ja))

        # dataset 9 -- ivc
        ivc = None
        if ivsd == 1:
            if model.verbose:
                print('   loading IVC...')
            ivc = Util2d.load(f, model, (1, njag), np.int, 'ivc',
                                   ext_unit_dict)
            ivc = ivc.array.reshape((njag))
            if model.verbose:
                print('   IVC {}'.format(ivc))

        # dataset 10a -- cl1
        cl1 = None
        if idsymrd == 1:
            if model.verbose:
                print('   loading CL1...')
            cl1 = Util2d.load(f, model, (1, njags), np.float32, 'cl1',
                                   ext_unit_dict)
            cl1 = cl1.array.reshape((njags))
            if model.verbose:
                print('   CL1 {}'.format(cl1))

        # dataset 10b -- cl2
        cl2 = None
        if idsymrd == 1:
            if model.verbose:
                print('   loading CL2...')
            cl2 = Util2d.load(f, model, (1, njags), np.float32, 'cl2',
                                   ext_unit_dict)
            cl2 = cl2.array.reshape((njags))
            if model.verbose:
                print('   CL2 {}'.format(cl2))

        # dataset 11 -- cl12
        cl12 = None
        if idsymrd == 0:
            if model.verbose:
                print('   loading CL12...')
            cl12 = Util2d.load(f, model, (1, njag), np.float32, 'cl12',
                                   ext_unit_dict)
            cl12 = cl12.array.reshape((njag))
            if model.verbose:
                print('   CL12 {}'.format(cl12))

        # dataset 12 -- fahl
        fahl = None
        if idsymrd == 0:
            n = njag
        elif idsymrd == 1:
            n = njags
        if model.verbose:
            print('   loading FAHL...')
        fahl = Util2d.load(f, model, (1, n), np.float32, 'fahl',
                               ext_unit_dict)
        fahl = fahl.array.reshape((n))
        if model.verbose:
            print('   FAHL {}'.format(fahl))

        # dataset 7 -- stress period info
        if model.verbose:
            print('   loading stress period data...')
        perlen = []
        nstp = []
        tsmult = []
        steady = []
        for k in range(nper):
            line = f.readline()
            a1, a2, a3, a4 = line.strip().split()[0:4]
            a1 = float(a1)
            a2 = int(a2)
            a3 = float(a3)
            if a4.upper() == 'TR':
                a4 = False
            else:
                a4 = True
            perlen.append(a1)
            nstp.append(a2)
            tsmult.append(a3)
            steady.append(a4)
        if model.verbose:
            print('   PERLEN {}'.format(perlen))
            print('   NSTP {}'.format(nstp))
            print('   TSMULT {}'.format(tsmult))
            print('   STEADY {}'.format(steady))

        # create dis object instance
        disu = ModflowDisU(model, nodes=nodes, nlay=nlay, njag=njag, ivsd=ivsd,
                           nper=nper, itmuni=itmuni, lenuni=lenuni,
                           idsymrd=idsymrd, laycbd=laycbd, nodelay=nodelay,
                           top=top, bot=bot, area=area, iac=iac, ja=ja,
                           ivc=ivc, cl1=cl1, cl2=cl2, cl12=cl12, fahl=fahl,
                           perlen=perlen, nstp=nstp, tsmult=tsmult,
                           steady=steady)

        # return dis object instance
        return disu
Пример #3
0
    def load(f, model, nper=1, nrow=1, ncol=1, ext_unit_dict=None):
        """

        Parameters
        ----------
        f : str
            filename
        model : mf88 object
        nper : int
            number of stress periods
        nrow : int
            number of model rows
        ncol : int
            number of model columns
        ext_unit_dict : dict
            Dictionary of unit and file names

        Returns
        -------
            Modflow88Rch object
        """

        if model.verbose:
            sys.stdout.write('loading bas6 package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')

        if model.nrow_ncol_nlay_nper != (0, 0, 0, 0):
            nrow, ncol, nlay, nper = model.nrow_ncol_nlay_nper

        t = f.readline().strip().split()
        nevtop, ievtcb = int(t[0]), int(t[1])

        surf = {}
        evtr = {}
        exdp = {}
        ievt = {}
        for per in range(nper):

            t = f.readline().strip().split()

            insurf, inevtr, inexdp = int(t[0]), int(t[1]), int(t[2])

            inievt = -999
            if nevtop == 2:
                inievt = int(t[3])

            if insurf < 0:
                surf[per] = surf[per - 1]
            else:
                surf[per] = Util2d.load(f, model, (nrow, ncol), np.float32,
                                        'surf', ext_unit_dict)

            if inevtr < 0:
                evtr[per] = evtr[per - 1]
            else:
                evtr[per] = Util2d.load(f, model, (nrow, ncol), np.float32,
                                        'evtr', ext_unit_dict)

            if inexdp < 0:
                exdp[per] = exdp[per - 1]
            else:
                exdp[per] = Util2d.load(f, model, (nrow, ncol), np.float32,
                                        'exdp', ext_unit_dict)

            if nevtop == 2:
                if inievt < 0:
                    ievt[per] = ievt[per - 1]
                else:
                    ievt[per] = Util2d.load(f, model, (nrow, ncol), np.int32,
                                            'ievt', ext_unit_dict)

        return Modflow88Evt(model, nevtop, ievtcb, surf, evtr, exdp, ievt)
Пример #4
0
    def load(f, model, nper=1, nrow=1, ncol=1, ext_unit_dict=None):
        """

        Parameters
        ----------
        f : str
            filename
        model : mf88 object
        nper : int
            number of stress periods
        nrow : int
            number of model rows
        ncol : int
            number of model columns
        ext_unit_dict : dict
            Dictionary of unit and file names

        Returns
        -------
            Modflow88Rch object
        """

        if model.verbose:
            sys.stdout.write('loading bas6 package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')

        if model.nrow_ncol_nlay_nper != (0, 0, 0, 0):
            nrow, ncol, nlay, nper = model.nrow_ncol_nlay_nper

        t = f.readline().strip().split()
        nrchop, irchcb = int(t[0]), int(t[1])

        rech = {}
        irch = {}

        for per in range(nper):
            t = f.readline().strip().split()
            inrech, inirech = int(t[0]), int(t[1])

            if inrech < 0:
                rech[per] = rech[per - 1]

            else:
                arr = Util2d.load(f, model, (nrow, ncol), np.float32, 'rech',
                                  ext_unit_dict)

                rech[per] = arr

            if nrchop == 2:
                if inirech < 0:
                    irch[per] = irch[per - 1]

                else:
                    arr = Util2d.load(f, model, (nrow, ncol), np.int32, "irch",
                                      ext_unit_dict)

                    irch[per] = arr

        return Modflow88Rch(model, nrchop, irchcb, rech, irch)
Пример #5
0
    def load(f, model, nper=None, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.modflow.mf.Modflow`) to
            which this package will be added.
        nper : int
            The number of stress periods.  If nper is None, then nper will be
            obtained from the model object. (default is None).
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        rch : ModflowRch object
            ModflowRch object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> rch = flopy.modflow.ModflowRch.load('test.rch', m)

        """
        if model.verbose:
            sys.stdout.write('loading rch package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        npar = 0
        if "parameter" in line.lower():
            raw = line.strip().split()
            npar = np.int(raw[1])
            if npar > 0:
                if model.verbose:
                    print('   Parameters detected. Number of parameters = ', npar)
            line = f.readline()
        # dataset 2
        t = line.strip().split()
        nrchop = int(t[0])
        ipakcb = 0
        try:
            if int(t[1]) != 0:
                model.add_pop_key_list(int(t[1]))
                ipakcb = 53
        except:
            pass

        # dataset 3 and 4 - parameters data
        pak_parms = None
        if npar > 0:
            pak_parms = mfparbc.loadarray(f, npar, model.verbose)

        if nper is None:
            nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        # read data for every stress period
        rech = {}
        irch = None
        if nrchop == 2:
            irch = {}
        current_rech = []
        current_irch = []
        for iper in range(nper):
            line = f.readline()
            t = line.strip().split()
            inrech = int(t[0])
            if nrchop == 2:
                inirch = int(t[1])
            if inrech >= 0:
                if npar == 0:
                    if model.verbose:
                        print('   loading rech stress period {0:3d}...'.format(iper + 1))
                    t = Util2d.load(f, model, (nrow, ncol), np.float32, 'rech', ext_unit_dict)
                else:
                    parm_dict = {}
                    for ipar in range(inrech):
                        line = f.readline()
                        t = line.strip().split()
                        pname = t[0].lower()
                        try:
                            c = t[1].lower()
                            instance_dict = pak_parms.bc_parms[pname][1]
                            if c in instance_dict:
                                iname = c
                            else:
                                iname = 'static'
                        except:
                            iname = 'static'
                        parm_dict[pname] = iname
                    t = mfparbc.parameter_bcfill(model, (nrow, ncol), parm_dict, pak_parms)

                current_rech = t
            rech[iper] = current_rech
            if nrchop == 2:
                if inirch >= 0:
                    if model.verbose:
                        print('   loading irch stress period {0:3d}...'.format(
                            iper + 1))
                    t = Util2d.load(f, model, (nrow, ncol), np.int, 'irch',
                                    ext_unit_dict)
                    current_irch = t
                irch[iper] = current_irch
        rch = ModflowRch(model, nrchop=nrchop, ipakcb=ipakcb, rech=rech,
                         irch=irch)
        return rch
Пример #6
0
    def __init__(self,
                 model,
                 iss=1,
                 ibcfcb=90,
                 laycon=(0, ),
                 trpy=(1., ),
                 delr=(1., ),
                 delc=(1., ),
                 sf1=1.,
                 tran=1.,
                 hy=1.,
                 bot=1.,
                 vcont=1.,
                 sf2=1.,
                 top=1.):

        unitnumber = [1, ibcfcb]
        filenames = [None, None]
        name = [Modflow88Bcf.ftype()]
        units = [unitnumber[0]]
        extra = [""]
        fname = [filenames[0]]
        extension = "bas"

        super(Modflow88Bcf, self).__init__(model,
                                           extension=extension,
                                           name=name,
                                           unit_number=units,
                                           extra=extra,
                                           filenames=fname)

        nrow, ncol, nlay, nper = model.nrow_ncol_nlay_nper

        self.iss = iss
        self.ibcfcb = ibcfcb
        self.laycon = Util2d(model, (nlay, ),
                             np.int32,
                             laycon,
                             name='laycon',
                             locat=self.unit_number[0])
        self.trpy = Util2d(model, (nlay, ),
                           np.float32,
                           trpy,
                           name='Anisotropy factor',
                           locat=self.unit_number[0])
        self.delr = Util2d(model, (ncol, ),
                           np.float32,
                           delr,
                           name='delr',
                           locat=self.unit_number[0])
        self.delc = Util2d(model, (nrow, ),
                           np.float32,
                           delc,
                           name='delc',
                           locat=self.unit_number[0])
        self.sf1 = Util3d(model, (nlay, nrow, ncol),
                          np.float32,
                          sf1,
                          'Primary Storage Coefficient',
                          locat=self.unit_number[0])
        self.tran = Util3d(model, (nlay, nrow, ncol),
                           np.float32,
                           tran,
                           'Transmissivity',
                           locat=self.unit_number[0])
        self.hy = Util3d(model, (nlay, nrow, ncol),
                         np.float32,
                         hy,
                         'Horizontal Hydraulic Conductivity',
                         locat=self.unit_number[0])
        self.bot = Util3d(model, (nlay, nrow, ncol),
                          np.float32,
                          bot,
                          'bot',
                          locat=self.unit_number[0])
        self.vcont = Util3d(model, (nlay - 1, nrow, ncol),
                            np.float32,
                            vcont,
                            'Vertical Conductance',
                            locat=self.unit_number[0])
        self.sf2 = Util3d(model, (nlay, nrow, ncol),
                          np.float32,
                          sf2,
                          'Secondary Storage Coefficient',
                          locat=self.unit_number[0])
        self.top = Util3d(model, (nlay, nrow, ncol),
                          np.float32,
                          top,
                          'top',
                          locat=self.unit_number[0])

        self.parent.add_package(self)
Пример #7
0
    def load(f, model, nper=None, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.seawat.swt.Seawat`) to
            which this package will be added.
        nper : int
            The number of stress periods.  If nper is None, then nper will be
            obtained from the model object. (default is None).
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        vdf : SeawatVdf object
            SeawatVdf object.

        Examples
        --------

        >>> import flopy
        >>> mf = flopy.modflow.Modflow()
        >>> dis = flopy.modflow.ModflowDis(mf)
        >>> mt = flopy.mt3d.Mt3dms()
        >>> swt = flopy.seawat.Seawat(modflowmodel=mf, mt3dmsmodel=mt)
        >>> vdf = flopy.seawat.SeawatVdf.load('test.vdf', m)

        """

        if model.verbose:
            sys.stdout.write('loading vdf package file...\n')

        # Open file, if necessary
        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')

        # Dataset 0 -- comment line
        while True:
            line = f.readline()
            if line[0] != '#':
                break

        # Determine problem dimensions
        nrow, ncol, nlay, nper = model.mf.get_nrow_ncol_nlay_nper()

        # Item 1: MT3DRHOFLG MFNADVFD NSWTCPL IWTABLE - line already read above
        if model.verbose:
            print('   loading MT3DRHOFLG MFNADVFD NSWTCPL IWTABLE...')
        t = line.strip().split()
        mt3drhoflg = int(t[0])
        mfnadvfd = int(t[1])
        nswtcpl = int(t[2])
        iwtable = int(t[3])
        if model.verbose:
            print('   MT3DRHOFLG {}'.format(mt3drhoflg))
            print('   MFNADVFD {}'.format(mfnadvfd))
            print('   NSWTCPL {}'.format(nswtcpl))
            print('   IWTABLE {}'.format(iwtable))

        # Item 2 -- DENSEMIN DENSEMAX
        if model.verbose:
            print('   loading DENSEMIN DENSEMAX...')
        line = f.readline()
        t = line.strip().split()
        densemin = float(t[0])
        densemax = float(t[1])

        # Item 3 -- DNSCRIT
        if model.verbose:
            print('   loading DNSCRIT...')
        dnscrit = None
        if nswtcpl > 1 or nswtcpl == -1:
            line = f.readline()
            t = line.strip().split()
            dnscrit = float(t[0])

        # Item 4 -- DENSEREF DRHODC
        drhodprhd = None
        prhdref = None
        nsrhoeos = None
        mtrhospec = None
        crhoref = None
        if mt3drhoflg >= 0:
            if model.verbose:
                print('   loading DENSEREF DRHODC(1)...')
            line = f.readline()
            t = line.strip().split()
            denseref = float(t[0])
            drhodc = float(t[1])
        else:
            if model.verbose:
                print('   loading DENSEREF DRHODPRHD PRHDREF...')
            line = f.readline()
            t = line.strip().split()
            denseref = float(t[0])
            drhodprhd = float(t[1])
            prhdref = float(t[2])

            if model.verbose:
                print('   loading NSRHOEOS...')
            line = f.readline()
            t = line.strip().split()
            nsrhoeos = int(t[0])

            if model.verbose:
                print('    loading MTRHOSPEC DRHODC CRHOREF...')
            mtrhospec = []
            drhodc = []
            crhoref = []
            for i in range(nsrhoeos):
                line = f.readline()
                t = line.strip().split()
                mtrhospec.append(int(t[0]))
                drhodc.append(float(t[1]))
                crhoref.append(float(t[2]))

        # Item 5 -- FIRSTDT
        if model.verbose:
            print('   loading FIRSTDT...')
        line = f.readline()
        t = line.strip().split()
        firstdt = float(t[0])

        # Items 6 and 7 -- INDENSE DENSE
        indense = None
        dense = None
        if mt3drhoflg == 0:
            if model.verbose:
                print('   loading INDENSE...')
            line = f.readline()
            t = line.strip().split()
            indense = int(t[0])

            if indense > 0:
                dense = [0] * nlay
                for k in range(nlay):
                    if model.verbose:
                        print('   loading DENSE layer {0:3d}...'.format(k + 1))
                    t = Util2d.load(f, model.mf, (nrow, ncol), np.float32,
                                     'dense', ext_unit_dict)
                    dense[k] = t

        # Construct and return vdf package
        vdf = SeawatVdf(model, mt3drhoflg=mt3drhoflg, mfnadvfd=mfnadvfd,
                        nswtcpl=nswtcpl, iwtable=iwtable,
                        densemin=densemin, densemax=densemax,
                        dnscrit=dnscrit, denseref=denseref, drhodc=drhodc,
                        drhodprhd=drhodprhd, prhdref=prhdref,
                        nsrhoeos=nsrhoeos, mtrhospec=mtrhospec,
                        crhoref=crhoref, indense=indense, dense=dense)
        return vdf
Пример #8
0
    def load(f, model, nrow=None, ncol=None, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.modflow.mf.Modflow`) to
            which this package will be added.
        nrow : int
            number of rows. If not specified it will be retrieved from
            the model object. (default is None).
        ncol : int
            number of columns. If not specified it will be retrieved from
            the model object. (default is None).
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        zone : ModflowMult dict

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> mlt = flopy.modflow.ModflowMlt.load('test.mlt', m)

        """

        if model.verbose:
            sys.stdout.write('loading mult package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        #dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        #dataset 1
        t = line.strip().split()
        nml = int(t[0])

        #get nlay,nrow,ncol if not passed
        if nrow is None and ncol is None:
            nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()

        #read zone data
        mult_dict = collections.OrderedDict()
        for n in range(nml):
            line = f.readline()
            t = line.strip().split()
            if len(t[0]) > 10:
                mltnam = t[0][0:10].lower()
            else:
                mltnam = t[0].lower()
            if model.verbose:
                sys.stdout.write('   reading data for "{:<10s}" mult\n'.format(mltnam))
            readArray = True
            kwrd = None
            if len(t) > 1:
                if 'function' in t[1].lower() or 'expression' in t[1].lower():
                    readArray = False
                    kwrd = t[1].lower()
            # load data
            if readArray:
                t = Util2d.load(f, model, (nrow, ncol), np.float32, mltnam,
                                 ext_unit_dict)
                # add unit number to list of external files in ext_unit_dict to remove.
                if t.locat is not None:
                    model.add_pop_key_list(t.locat)
            else:
                line = f.readline()
                t = [kwrd, line]
                t = ModflowMlt.mult_function(mult_dict, line)
            mult_dict[mltnam] = t

        # create mlt dictionary
        mlt = ModflowMlt(model, mult_dict=mult_dict)

        return mlt
Пример #9
0
    def load(f, model, ext_unit_dict=None):
        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')

        # A1
        if model.verbose:
            print('   loading COMMENT LINES A1 AND A2...')
        line = f.readline()
        if model.verbose:
            print('A1: '.format(line.strip()))

        # A2
        line = f.readline()
        if model.verbose:
            print('A2: '.format(line.strip()))

        # A3
        if model.verbose:
            print('   loading NLAY, NROW, NCOL, NPER, NCOMP, MCOMP...')
        line = f.readline()
        nlay = int(line[0:10])
        nrow = int(line[11:20])
        ncol = int(line[21:30])
        nper = int(line[31:40])
        try:
            ncomp = int(line[41:50])
        except:
            ncomp = 1
        try:
            mcomp = int(line[51:60])
        except:
            mcomp = 1
        if model.verbose:
            print('   NLAY {}'.format(nlay))
            print('   NROW {}'.format(nrow))
            print('   NCOL {}'.format(ncol))
            print('   NPER {}'.format(nper))
            print('   NCOMP {}'.format(ncomp))
            print('   MCOMP {}'.format(mcomp))

        if model.verbose:
            print('   loading TUNIT, LUNIT, MUNIT...')
        line = f.readline()
        tunit = line[0:4]
        lunit = line[4:8]
        munit = line[8:12]
        if model.verbose:
            print('   TUNIT {}'.format(tunit))
            print('   LUNIT {}'.format(lunit))
            print('   MUNIT {}'.format(munit))

        if model.verbose:
            print('   loading TRNOP...')
        trnop = f.readline()[:20].strip().split()
        if model.verbose:
            print('   TRNOP {}'.format(trnop))

        if model.verbose:
            print('   loading LAYCON...')
        laycon = np.empty((nlay), np.int)
        laycon = read1d(f, laycon)
        if model.verbose:
            print('   LAYCON {}'.format(laycon))

        if model.verbose:
            print('   loading DELR...')
        delr = Util2d.load(f, model, (ncol, 1), np.float32, 'delr',
                            ext_unit_dict)
        if model.verbose:
            print('   DELR {}'.format(delr))

        if model.verbose:
            print('   loading DELC...')
        delc = Util2d.load(f, model, (nrow, 1), np.float32, 'delc',
                            ext_unit_dict)
        if model.verbose:
            print('   DELC {}'.format(delc))

        if model.verbose:
            print('   loading HTOP...')
        htop = Util2d.load(f, model, (nrow, ncol), np.float32, 'htop',
                            ext_unit_dict)
        if model.verbose:
            print('   HTOP {}'.format(htop))

        if model.verbose:
            print('   loading DZ...')
        dz = Util3d.load(f, model, (nlay, nrow, ncol), np.float32, 'dz',
                          ext_unit_dict)
        if model.verbose:
            print('   DZ {}'.format(dz))

        if model.verbose:
            print('   loading PRSITY...')
        prsity = Util3d.load(f, model, (nlay, nrow, ncol), np.float32, 'prsity',
                              ext_unit_dict)
        if model.verbose:
            print('   PRSITY {}'.format(prsity))

        if model.verbose:
            print('   loading ICBUND...')
        icbund = Util3d.load(f, model, (nlay, nrow, ncol), np.int, 'icbund',
                              ext_unit_dict)
        if model.verbose:
            print('   ICBUND {}'.format(icbund))

        if model.verbose:
            print('   loading SCONC...')
        kwargs = {}
        sconc = Util3d.load(f, model, (nlay, nrow, ncol), np.float32, 'sconc1',
                             ext_unit_dict)
        if ncomp > 1:
            for icomp in range(2, ncomp + 1):
                name = "sconc" + str(icomp)
                if model.verbose:
                    print('   loading {}...'.format(name))
                u3d = Util3d.load(f, model, (nlay, nrow, ncol), np.float32,
                                   name, ext_unit_dict)
                kwargs[name] = u3d
        if model.verbose:
            print('   SCONC {}'.format(sconc))

        if model.verbose:
            print('   loading CINACT, THCKMIN...')
        line = f.readline()
        cinact = float(line[0:10])
        try:
            thkmin = float(line[10:20])
        except:
            thkmin = 0.01
        if model.verbose:
            print('   CINACT {}'.format(cinact))
            print('   THKMIN {}'.format(thkmin))

        if model.verbose:
            print('   loading IFMTCN, IFMTNP, IFMTRF, IFMTDP, SAVUCN...')
        line = f.readline()
        ifmtcn = int(line[0:10])
        ifmtnp = int(line[10:20])
        ifmtrf = int(line[20:30])
        ifmtdp = int(line[30:40])
        savucn = False
        if 't' in line[40:50].lower():
            savucn = True
        if model.verbose:
            print('   IFMTCN {}'.format(ifmtcn))
            print('   IFMTNP {}'.format(ifmtnp))
            print('   IFMTRF {}'.format(ifmtrf))
            print('   IFMTDP {}'.format(ifmtdp))
            print('   SAVUCN {}'.format(savucn))

        if model.verbose:
            print('   loading NPRS...')
        line = f.readline()
        nprs = int(line[0:10])
        if model.verbose:
            print('   NPRS {}'.format(nprs))

        timprs = None
        if nprs > 0:
            if model.verbose:
                print('   loading TIMPRS...')
            timprs = np.empty((nprs), dtype=np.float32)
            read1d(f, timprs)
            if model.verbose:
                print('   TIMPRS {}'.format(timprs))

        if model.verbose:
            print('   loading NOBS, NPROBS...')
        line = f.readline()
        nobs = int(line[0:10])
        try:
            nprobs = int(line[10:20])
        except:
            nprobs = 1
        if model.verbose:
            print('   NOBS {}'.format(nobs))
            print('   NPROBS {}'.format(nprobs))

        obs = None
        if nobs > 0:
            if model.verbose:
                print('   loading KOBS, IOBS, JOBS...')
            obs = []
            for l in range(nobs):
                line = f.readline()
                k = int(line[0:10])
                i = int(line[10:20])
                j = int(line[20:30])
                obs.append([k, i, j])
            obs = np.array(obs)
            if model.verbose:
                print('   OBS {}'.format(obs))

        if model.verbose:
            print('   loading CHKMAS, NPRMAS...')
        line = f.readline()
        chkmas = False
        if 't' in line[0:10].lower():
            chkmas = True
        try:
            nprmas = int(line[10:20])
        except:
            nprmas = 1
        if model.verbose:
            print('   CHKMAS {}'.format(chkmas))
            print('   NPRMAS {}'.format(nprmas))


        if model.verbose:
            print('   loading PERLEN, NSTP, TSMULT, TSLNGH, DT0, MXSTRN, TTSMULT, TTSMAX...')
        dt0, mxstrn, ttsmult, ttsmax = [], [], [], []
        perlen = []
        nstp = []
        tsmult = []
        tslngh = []
        ssflag = []
        for kper in range(nper):
            line = f.readline()
            perlen.append(float(line[0:10]))
            nstp.append(int(line[10:20]))
            tsmult.append(float(line[20:30]))
            sf = ' '
            ll = line[30:].strip().split()
            if len(ll) > 0:
                if 'sstate' in ll[0].lower():
                    sf = 'SState'
            ssflag.append(sf)

            if tsmult[-1] < 0:
                t = np.empty((nstp[-1]), dtype=np.float32)
                read1d(f, t)
                tslngh.append(t)
                raise Exception("tsmult <= 0 not supported")

            line = f.readline()
            dt0.append(float(line[0:10]))
            mxstrn.append(int(line[10:20]))
            ttsmult.append(float(line[20:30]))
            ttsmax.append(float(line[30:40]))

        if model.verbose:
            print('   PERLEN {}'.format(perlen))
            print('   NSTP {}'.format(nstp))
            print('   TSMULT {}'.format(tsmult))
            print('   SSFLAG {}'.format(ssflag))
            print('   TSLNGH {}'.format(tslngh))
            print('   DT0 {}'.format(dt0))
            print('   MXSTRN {}'.format(mxstrn))
            print('   TTSMULT {}'.format(ttsmult))
            print('   TTSMAX {}'.format(ttsmax))

        # Close the file
        f.close()

        btn = Mt3dBtn(model, nlay=nlay, nrow=nrow, ncol=ncol, nper=nper,
                      ncomp=ncomp, mcomp=mcomp, tunit=tunit,
                      laycon=laycon, delr=delr, delc=delc, htop=htop, dz=dz,
                      lunit=lunit, munit=munit, prsity=prsity, icbund=icbund,
                      sconc=sconc, cinact=cinact, thkmin=thkmin,
                      ifmtcn=ifmtcn, ifmtnp=ifmtnp, ifmtrf=ifmtrf,
                      ifmtdp=ifmtdp, savucn=savucn, nprs=nprs,
                      timprs=timprs, obs=obs, nprobs=nprobs, chkmas=chkmas,
                      nprmas=nprmas, perlen=perlen, nstp=nstp, tsmult=tsmult,
                      ssflag=ssflag, dt0=dt0, mxstrn=mxstrn, ttsmult=ttsmult,
                      ttsmax=ttsmax, **kwargs)
        return btn
Пример #10
0
    def load(f, model, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.modflow.mf.Modflow`) to
            which this package will be added.
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        dis : ModflowDis object
            ModflowDis object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> dis = flopy.modflow.ModflowDis.load('test.dis', m)

        """

        if model.verbose:
            sys.stdout.write('loading dis package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # dataset 1
        nlay, nrow, ncol, nper, itmuni, lenuni = line.strip().split()[0:6]
        nlay = int(nlay)
        nrow = int(nrow)
        ncol = int(ncol)
        nper = int(nper)
        itmuni = int(itmuni)
        lenuni = int(lenuni)
        # dataset 2 -- laycbd
        if model.verbose:
            print('   Loading dis package with:\n      ' + \
                  '{0} layers, {1} rows, {2} columns, and {3} stress periods'.format(nlay, nrow, ncol, nper))
            print('   loading laycbd...')
        laycbd = np.empty((nlay), dtype=np.int)
        d = 0
        while True:
            line = f.readline()
            raw = line.strip('\n').split()
            for val in raw:
                laycbd[d] = np.int(val)
                d += 1
                if d == nlay:
                    break
            if d == nlay:
                break
        # dataset 3 -- delr
        if model.verbose:
            print('   loading delr...')
        delr = Util2d.load(f, model, (1, ncol), np.float32, 'delr',
                            ext_unit_dict)
        delr = delr.array.reshape((ncol))
        #dataset 4 -- delc
        if model.verbose:
            print('   loading delc...')
        delc = Util2d.load(f, model, (1, nrow), np.float32, 'delc',
                            ext_unit_dict)
        delc = delc.array.reshape((nrow))
        #dataset 5 -- top
        if model.verbose:
            print('   loading top...')
        top = Util2d.load(f, model, (nrow, ncol), np.float32, 'top',
                           ext_unit_dict)
        #dataset 6 -- botm
        if model.verbose:
            print('   loading botm...')
        ncbd = laycbd.sum()
        if nlay > 1:
            botm = Util3d.load(f, model, (nlay + ncbd, nrow, ncol), np.float32,
                                'botm', ext_unit_dict)
        else:
            botm = Util3d.load(f, model, (nlay, nrow, ncol), np.float32, 'botm',
                                ext_unit_dict)
        #dataset 7 -- stress period info
        if model.verbose:
            print('   loading stress period data...')
        perlen = []
        nstp = []
        tsmult = []
        steady = []
        for k in range(nper):
            line = f.readline()
            a1, a2, a3, a4 = line.strip().split()[0:4]
            a1 = float(a1)
            a2 = int(a2)
            a3 = float(a3)
            if a4.upper() == 'TR':
                a4 = False
            else:
                a4 = True
            perlen.append(a1)
            nstp.append(a2)
            tsmult.append(a3)
            steady.append(a4)

        # create dis object instance
        dis = ModflowDis(model, nlay, nrow, ncol, nper, delr, delc, laycbd,
                         top, botm, perlen, nstp, tsmult, steady, itmuni,
                         lenuni)
        # return dis object instance
        return dis
Пример #11
0
    def load(f, model, nlay=None, nrow=None, ncol=None, nper=None,
             ncomp=None, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.mt3d.mt.Mt3dms`) to
            which this package will be added.
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        ssm :  Mt3dSsm object
            Mt3dSsm object.

        Examples
        --------

        >>> import flopy
        >>> mt = flopy.mt3d.Mt3dms()
        >>> ssm = flopy.mt3d.Mt3dSsm.load('test.ssm', m)

        """

        if model.verbose:
            sys.stdout.write('loading ssm package file...\n')

        # Open file, if necessary
        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')

        # Set dimensions if necessary
        if nlay is None:
            nlay = model.nlay
        if nrow is None:
            nrow = model.nrow
        if ncol is None:
            ncol = model.ncol
        if nper is None:
            nper = model.nper
        if ncomp is None:
            ncomp = model.ncomp

        # dtype
        dtype = Mt3dSsm.get_default_dtype(ncomp)

        # Dataset 0 -- comment line
        while True:
            line = f.readline()
            if line[0] != '#':
                break

        # Item D1: Dummy input line - line already read above
        if model.verbose:
            print('   loading FWEL, FDRN, FRCH, FEVT, FRIV, FGHB, (FNEW(n), n=1,4)...')
        fwel = line[0:2]
        fdrn = line[4:6]
        frch = line[6:8]
        fevt = line[8:10]
        friv = line[10:12]
        fghb = line[12:14]
        fnew1 = line[14:16]
        fnew2 = line[16:18]
        fnew3 = line[18:20]
        fnew4 = line[20:22]
        if model.verbose:
            print('   FWEL {}'.format(fwel))
            print('   FDRN {}'.format(fdrn))
            print('   FRCH {}'.format(frch))
            print('   FEVT {}'.format(fevt))
            print('   FRIV {}'.format(friv))
            print('   FGHB {}'.format(fghb))
            print('   FNEW1 {}'.format(fnew1))
            print('   FNEW2 {}'.format(fnew2))
            print('   FNEW3 {}'.format(fnew3))
            print('   FNEW4 {}'.format(fnew4))

        # Item D2: MXSS, ISSGOUT
        mxss = None
        if model.verbose:
            print('   loading MXSS, ISSGOUT...')
        line = f.readline()
        mxss = int(line[0:10])
        try:
            issgout = int(line[10:20])
        except:
            issgout = 0
        if model.verbose:
            print('   MXSS {}'.format(mxss))
            print('   ISSGOUT {}'.format(issgout))


        crch = None
        if 't' in frch.lower():
            crch = {0:0}

        cevt = None
        if 't' in fevt.lower():
            cevt = {0:0}

        stress_period_data = {}

        for iper in range(nper):

            if model.verbose:
                print("   loading ssm for kper {0:5d}".format(iper + 1))

            # Item D3: INCRCH
            incrch = -1
            if 't' in frch.lower():
                if model.verbose:
                    print('   loading INCRCH...')
                line = f.readline()
                incrch = int(line[0:10])

            # Item D4: CRCH
            if incrch >= 0:
                if model.verbose:
                    print('   loading CRCH...')
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'crch',
                                 ext_unit_dict)
                crch[iper] = t

            # Item D5: INCEVT
            incevt = -1
            if 't' in fevt.lower():
                if model.verbose:
                    print('   loading INCEVT...')
                line = f.readline()
                incevt = int(line[0:10])

            # Item D6: CEVT
            if incevt >= 0:
                if model.verbose:
                    print('   loading CEVT...')
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'cevt',
                                 ext_unit_dict)
                cevt[iper] = t

            # Item D7: NSS
            if model.verbose:
                print('   loading NSS...')
            line = f.readline()
            nss = int(line[0:10])

            # Item D8: KSS, ISS, JSS, CSS, ITYPE, (CSSMS(n),n=1,NCOMP)
            if model.verbose:
                print('   loading KSS, ISS, JSS, CSS, ITYPE, (CSSMS(n),n=1,NCOMP)...')
            current = 0
            if nss > 0:
                current = np.empty((nss), dtype=dtype)
                for ibnd in range(nss):
                    line = f.readline()
                    t = []
                    for ivar in range(5):
                        istart = ivar * 10
                        istop = istart + 10
                        t.append(line[istart:istop])
                    ncssms = len(current.dtype.names) - 5
                    if ncssms > 0:
                        tt = line[istop:].strip().split()
                        for ivar in range(ncssms):
                            t.append(tt[ivar])
                    current[ibnd] = tuple(t[:len(current.dtype.names)])
                # convert indices to zero-based
                current['k'] -= 1
                current['i'] -= 1
                current['j'] -= 1
                current = current.view(np.recarray)
            stress_period_data[iper] = current

        # Construct and return ssm package
        ssm = Mt3dSsm(model, crch=crch, cevt=cevt, mxss=mxss,
                      stress_period_data=stress_period_data)
        return ssm
Пример #12
0
    def load(f, model, nsfinit=None, nper=None, ncomp=None, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.mt3d.mt.Mt3dms`) to
            which this package will be added.
        nsfinit : int
            number of simulated stream reaches in the surface-water transport
            process.
        isfsolv : int
            Specifies the numerical technique that will be used to solve the
            transport problem in the surface water network.  The first release
            of MT3D-USGS (version 1.0) only allows for a finite-difference
            formulation and regardless of what value the user specifies, the
            variable defaults to 1, meaning the finite-difference solution is
            invoked.
        wimp : float
            Is the stream solver time weighting factor.  Ranges between 0.0 and
            1.0.  Values of 0.0, 0.5, or 1.0 correspond to explicit,
            Crank-Nicolson, and fully implicit schemes, respectively.
        wups : float
            Is the space weighting factor employed in the stream network solver.
            Ranges between 0.0 and 1.0.  Values of 0.0 and 1.0 correspond to a
            central-in-space and upstream weighting factors, respectively.
        cclosesf : float
            Is the closure criterion for the SFT solver
        mxitersf : int
            Limits the maximum number of iterations the SFT solver can use to
            find a solution of the stream transport problem.
        crntsf : float
            Is the Courant constraint specific to the SFT time step, its value
            has no bearing upon the groundwater transport solution time step.

        Returns
        -------
        sft : MT3D-USGS object
            MT3D-USGS object

        Examples
        --------

        >>> import os
        >>> import flopy

        >>> os.chdir(r'C:\EDM_LT\GitHub\mt3d-usgs\autotest\temp\CrnkNic')
        >>> mf = flopy.modflow.Modflow.load('CrnkNic_mf.nam', load_only=['dis', 'bas6'])
        >>> sfr = flopy.modflow.ModflowSfr2.load('CrnkNic.sfr2', mf)
        >>> chk = sfr.check()


        """
        if model.verbose:
            sys.stdout.write('loading sft package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')

        # Set default nlay values
        nlay = None
        nrow = None
        ncol = None

        # Set dimensions if necessary
        if nlay is None:
            nlay = model.nlay
        if nrow is None:
            nrow = model.nrow
        if ncol is None:
            ncol = model.ncol
        if nper is None:
            nper = model.nper
        if ncomp is None:
            ncomp = model.ncomp

        dtype = Mt3dSft.get_default_dtype(ncomp)

        # Item 1 (NSFINIT, MXSFBC, ICBCSF, IOUTOBS, IETSFR)
        line = f.readline()
        if line[0] == '#':
            if model.verbose:
                print('   SFT package currently does not support comment lines...')
                sys.exit()

        if model.verbose:
            print('   loading nsfinit, mxsfbc, icbcsf, ioutobs, ietsfr...')
        vals = line.strip().split()

        nsfinit = int(vals[0])
        mxsfbc = int(vals[1])
        icbcsf = int(vals[2])
        ioutobs = int(vals[3])
        ietsfr = int(vals[4])

        if model.verbose:
            print('   NSFINIT {}'.format(nsfinit))
            print('   MXSFBC {}'.format(mxsfbc))
            print('   ICBCSF {}'.format(icbcsf))
            print('   IOUTOBS {}'.format(ioutobs))
            print('   IETSFR {}'.format(ietsfr))
            if ietsfr == 0:
                print('   Mass does not exit the model via simulated stream evaporation ')
            else:
                print('   Mass exits the stream network via simulated stream evaporation ')

        # Item 2 (ISFSOLV, WIMP, WUPS, CCLOSESF, MXITERSF, CRNTSF)
        line = f.readline()
        if model.verbose:
            print('   loading isfsolv, wimp, wups, cclosesf, mxitersf, crntsf...')

        vals = line.strip().split()

        if len(vals) < 6 and model.verbose:
            print('   not enough values specified in item 2 of SFT input \
                      file, exiting...')
            sys.exit()
        else:
            isfsolv = int(vals[0])
            wimp = float(vals[1])
            wups = float(vals[2])
            cclosesf = float(vals[3])
            mxitersf = int(vals[4])
            crntsf = float(vals[5])
        if isfsolv != 1:
            isfsolv = 1
            print('   Resetting isfsolv to 1')
            print('   In version 1.0 of MT3D-USGS, isfsov=1 is only option')

        if model.verbose:
            print('   ISFSOLV {}'.format(isfsolv))
            print('   WIMP {}'.format(wimp))
            print('   WUPS {}'.format(wups))
            print('   CCLOSESF {}'.format(cclosesf))
            print('   MXITERSF {}'.format(mxitersf))
            print('   CRNTSF {}'.format(crntsf))

        # Item 3 (COLDSF(NRCH)) Initial concentration
        if model.verbose:
            print('   loading NSFINIT...')

            if model.free_format:
                print('   Using MODFLOW style array reader utilities to read \
                      NSFINIT')
            elif model.array_format == None:
                print('   Using historic MT3DMS array reader utilities to \
                      read NSFINIT')

        # Because SFT package is a new package, it only accepts free format
        # Don't need to worry about reading fixed format here
        coldsf = Util2d.load(f, model, (1, nsfinit), np.float32, 'nsfinit',
                                 ext_unit_dict)

        # Item 4 (DISPSF(NRCH)) Reach-by-reach dispersion
        if model.verbose:
            if model.free_format:
                print('   Using MODFLOW style array reader utilities to read \
                      DISPSF')
            elif model.free_format is None:
                print('   Using historic MT3DMS array reader utilities to \
                      read DISPSF')

        # Because SFT package is a new package, it only accepts free format.
        # Don't need to worry about reading fixed format here
        dispsf = Util2d.load(f, model, (1, nsfinit), np.float32, 'dispsf',
                                 ext_unit_dict)

        # Item 5 NOBSSF
        if model.verbose:
            print('   loading NOBSSF...')
        line = f.readline()
        m_arr = line.strip().split()
        nobssf = int(m_arr[0])
        if model.verbose:
            print('   NOBSSF {}'.format(nobssf))

        # If NOBSSF > 0, store observation segment & reach (Item 6)
        obs_sf = []
        if nobssf > 0:
            if model.verbose:
                print('   loading {} observation locations given by ISOBS, '\
                          'IROBS...'.format(nobssf))
            for i in range(nobssf):
                line = f.readline()
                m_arr = line.strip().split()
                obs_sf.append([int(m_arr[0]), int(m_arr[1])])
            obs_sf = np.array(obs_sf)
            if model.verbose:
                print('   Surface water concentration observation locations:')
                print('   {}',format(obs_sf))
        else:
            if model.verbose:
                print('   No observation points specified.')

        sf_stress_period_data = {}

        for iper in range(nper):

            # Item 7 NTMP (Transient data)
            if model.verbose:
                print('   loading NTMP...')
            line = f.readline()
            m_arr = line.strip().split()
            ntmp = int(m_arr[0])

            # Item 8 ISEGBC, IRCHBC, ISFBCTYP, CBCSF
            if model.verbose:
                print('   loading {} instances of ISEGBC, IRCHBC, ISFBCTYP, ' \
                        'CBCSF...'.format(ntmp))
            current_sf = 0
            if ntmp > 0:
                current_sf = np.empty((ntmp), dtype=dtype)
                for ibnd in range(ntmp):
                    line = f.readline()
                    m_arr = line.strip().split()
                    t = []
                    for ivar in range(3):  # First three terms are not variable
                        t.append(m_arr[ivar])
                    cbcsf = len(current_sf.dtype.names) - 3
                    if cbcsf > 0:
                        for ivar in range(cbcsf):
                            t.append(m_arr[ivar + 3])
                    current_sf[ibnd] = tuple(t[:len(current_sf.dtype.names)])
                # Convert ISEG IRCH indices to zero-based
                current_sf['isegbc'] -= 1
                current_sf['irchbc'] -= 1
                current_sf = current_sf.view(np.recarray)
                sf_stress_period_data[iper] = current_sf
            else:
                if model.verbose:
                    print('   No transient boundary conditions specified')
                pass

        # Construct and return SFT package
        sft = Mt3dSft(model, nsfinit=nsfinit, mxsfbc=mxsfbc, icbcsf=icbcsf,
                      ioutobs=ioutobs, ietsfr=ietsfr, isfsolv=isfsolv,
                      wimp=wimp, cclosesf=cclosesf, mxitersf=mxitersf,
                      crntsf=crntsf, coldsf=coldsf, dispsf=dispsf, nobssf=nobssf,
                      obs_sf=obs_sf, sf_stress_period_data=sf_stress_period_data)
        return sft
Пример #13
0
    def load(f, model, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.modflow.mf.Modflow`) to
            which this package will be added.
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        dis : ModflowUPW object
            ModflowLpf object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> upw = flopy.modflow.ModflowUpw.load('test.upw', m)

        """

        if model.verbose:
            sys.stdout.write('loading upw package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        # Item 1: IBCFCB, HDRY, NPLPF - line already read above
        if model.verbose:
            print('   loading ipakcb, HDRY, NPUPW, IPHDRY...')
        t = line.strip().split()
        ipakcb, hdry, npupw, iphdry = int(t[0]), float(t[1]), int(t[2]), int(t[3])
        if ipakcb != 0:
            model.add_pop_key_list(ipakcb)
            ipakcb = 53
        # options
        noparcheck = False
        if len(t) > 3:
            for k in range(3, len(t)):
                if 'NOPARCHECK' in t[k].upper():
                    noparcheck = True
        # LAYTYP array
        if model.verbose:
            print('   loading LAYTYP...')
        line = f.readline()
        t = line.strip().split()
        laytyp = np.array((t[0:nlay]), dtype=np.int)
        # LAYAVG array
        if model.verbose:
            print('   loading LAYAVG...')
        line = f.readline()
        t = line.strip().split()
        layavg = np.array((t[0:nlay]), dtype=np.int)
        # CHANI array
        if model.verbose:
            print('   loading CHANI...')
        line = f.readline()
        t = line.strip().split()
        chani = np.array((t[0:nlay]), dtype=np.float32)
        # LAYVKA array
        if model.verbose:
            print('   loading LAYVKA...')
        line = f.readline()
        t = line.strip().split()
        layvka = np.array((t[0:nlay]), dtype=np.int)
        # LAYWET array
        if model.verbose:
            print('   loading LAYWET...')
        line = f.readline()
        t = line.strip().split()
        laywet = np.array((t[0:nlay]), dtype=np.int)
        # Item 7: WETFCT, IWETIT, IHDWET
        wetfct, iwetit, ihdwet = None, None, None
        iwetdry = laywet.sum()
        if iwetdry > 0:
            raise Exception('LAYWET should be 0 for UPW')

        # get parameters
        par_types = []
        if npupw > 0:
            par_types, parm_dict = mfpar.load(f, nplpf, model.verbose)

        # get arrays
        transient = not model.get_package('DIS').steady.all()
        hk = [0] * nlay
        hani = [0] * nlay
        vka = [0] * nlay
        ss = [0] * nlay
        sy = [0] * nlay
        vkcb = [0] * nlay
        for k in range(nlay):
            if model.verbose:
                print('   loading hk layer {0:3d}...'.format(k + 1))
            if 'hk' not in par_types:
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'hk',
                                 ext_unit_dict)
            else:
                line = f.readline()
                t = mfpar.parameter_fill(model, (nrow, ncol), 'hk', parm_dict, findlayer=k)
            hk[k] = t
            if chani[k] < 1:
                if model.verbose:
                    print('   loading hani layer {0:3d}...'.format(k + 1))
                if 'hani' not in par_types:
                    t = Util2d.load(f, model, (nrow, ncol), np.float32, 'hani',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'hani', parm_dict, findlayer=k)
                hani[k] = t
            if model.verbose:
                print('   loading vka layer {0:3d}...'.format(k + 1))
            if 'vka' not in par_types and 'vani' not in par_types:
                key = 'vka'
                if layvka[k] != 0:
                    key = 'vani'
                t = Util2d.load(f, model, (nrow, ncol), np.float32, key,
                                 ext_unit_dict)
            else:
                line = f.readline()
                key = 'vka'
                if 'vani' in par_types:
                    key = 'vani'
                t = mfpar.parameter_fill(model, (nrow, ncol), key, parm_dict, findlayer=k)
            vka[k] = t
            if transient:
                if model.verbose:
                    print('   loading ss layer {0:3d}...'.format(k + 1))
                if 'ss' not in par_types:
                    t = Util2d.load(f, model, (nrow, ncol), np.float32, 'ss',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'ss', parm_dict, findlayer=k)
                ss[k] = t
                if laytyp[k] != 0:
                    if model.verbose:
                        print('   loading sy layer {0:3d}...'.format(k + 1))
                    if 'sy' not in par_types:
                        t = Util2d.load(f, model, (nrow, ncol), np.float32, 'sy',
                                         ext_unit_dict)
                    else:
                        line = f.readline()
                        t = mfpar.parameter_fill(model, (nrow, ncol), 'sy', parm_dict, findlayer=k)
                    sy[k] = t
            if model.get_package('DIS').laycbd[k] > 0:
                if model.verbose:
                    print('   loading vkcb layer {0:3d}...'.format(k + 1))
                if 'vkcb' not in par_types:
                    t = Util2d.load(f, model, (nrow, ncol), np.float32, 'vkcb',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'vkcb', parm_dict, findlayer=k)
                vkcb[k] = t

        # create upw object
        upw = ModflowUpw(model, ipakcb=ipakcb, iphdry=iphdry, hdry=hdry,
                         noparcheck=noparcheck,
                         laytyp=laytyp, layavg=layavg, chani=chani,
                         layvka=layvka, laywet=laywet,
                         hk=hk, hani=hani, vka=vka, ss=ss, sy=sy, vkcb=vkcb)

        # return upw object
        return upw
Пример #14
0
    def load(f, model, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.modflow.mf.Modflow`) to
            which this package will be added.
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        swi2 : ModflowSwi2 object

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> swi2 = flopy.modflow.ModflowSwi2.load('test.swi2', m)

        """

        if model.verbose:
            sys.stdout.write('loading swi2 package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()

        # --read dataset 1
        if model.verbose:
            sys.stdout.write('  loading swi2 dataset 1\n')
        t = line.strip().split()
        nsrf = int(t[0])
        istrat = int(t[1])
        nobs = int(t[2])
        if int(t[3]) > 0:
            model.add_pop_key_list(int(t[3]))
            iswizt = 55
        if int(t[4]) > 0:
            model.add_pop_key_list(int(t[4]))
            ipakcb = 56
        else:
            ipakcb = 0
        iswiobs = 0
        if int(t[5]) > 0:
            model.add_pop_key_list(int(t[5]))
            iswiobs = 1051
        options = []
        adaptive = False
        for idx in range(6, len(t)):
            if '#' in t[idx]:
                break
            options.append(t[idx])
            if 'adaptive' in t[idx].lower():
                adaptive = True

        # read dataset 2a
        if model.verbose:
            sys.stdout.write('  loading swi2 dataset 2a\n')
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        t = line.strip().split()
        nsolver = int(t[0])
        iprsol = int(t[1])
        mutsol = int(t[2])

        # read dataset 2b
        solver2params = {}
        if nsolver == 2:
            if model.verbose:
                sys.stdout.write('  loading swi2 dataset 2b\n')
            while True:
                line = f.readline()
                if line[0] != '#':
                    break
            t = line.strip().split()
            solver2params['mxiter'] = int(t[0])
            solver2params['iter1'] = int(t[1])
            solver2params['npcond'] = int(t[2])
            solver2params['zclose'] = float(t[3])
            solver2params['rclose'] = float(t[4])
            solver2params['relax'] = float(t[5])
            solver2params['nbpol'] = int(t[6])
            solver2params['damp'] = float(t[7])
            solver2params['dampt'] = float(t[8])

        # read dataset 3a
        if model.verbose:
            sys.stdout.write('  loading swi2 dataset 3a\n')
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        t = line.strip().split()
        toeslope = float(t[0])
        tipslope = float(t[1])
        alpha = None
        beta = 0.1
        if len(t) > 2:
            try:
                alpha = float(t[2])
                beta = float(t[3])
            except:
                pass

        # read dataset 3b
        nadptmx, nadptmn, adptfct = None, None, None
        if adaptive:
            if model.verbose:
                sys.stdout.write('  loading swi2 dataset 3b\n')
            while True:
                line = f.readline()
                if line[0] != '#':
                    break
            t = line.strip().split()
            nadptmx = int(t[0])
            nadptmn = int(t[1])
            adptfct = float(t[2])

        # read dataset 4
        if model.verbose:
            print('   loading nu...')
        if istrat == 1:
            nnu = nsrf + 1
        else:
            nnu = nsrf + 2
        while True:
            ipos = f.tell()
            line = f.readline()
            if line[0] != '#':
                f.seek(ipos)
                break
        nu = Util2d.load(f, model, (1, nnu), np.float32, 'nu',
                         ext_unit_dict)
        nu = nu.array.reshape((nnu))

        # read dataset 5
        if model.verbose:
            print('   loading initial zeta surfaces...')
        while True:
            ipos = f.tell()
            line = f.readline()
            if line[0] != '#':
                f.seek(ipos)
                break
        zeta = []
        for n in range(nsrf):
            ctxt = 'zeta_surf{:02d}'.format(n + 1)
            zeta.append(Util3d.load(f, model, (nlay, nrow, ncol),
                                    np.float32, ctxt, ext_unit_dict))

        # read dataset 6
        if model.verbose:
            print('   loading initial ssz...')
        while True:
            ipos = f.tell()
            line = f.readline()
            if line[0] != '#':
                f.seek(ipos)
                break
        ssz = Util3d.load(f, model, (nlay, nrow, ncol), np.float32,
                          'ssz', ext_unit_dict)

        # read dataset 7
        if model.verbose:
            print('   loading initial isource...')
        while True:
            ipos = f.tell()
            line = f.readline()
            if line[0] != '#':
                f.seek(ipos)
                break
        isource = Util3d.load(f, model, (nlay, nrow, ncol), np.int,
                              'isource', ext_unit_dict)

        # read dataset 8
        obsname = []
        obslrc = []
        if nobs > 0:
            if model.verbose:
                print('   loading observation locations...')
            while True:
                line = f.readline()
                if line[0] != '#':
                    break
            for i in range(nobs):
                if i > 0:
                    try:
                        line = f.readline()
                    except:
                        break
                t = line.strip().split()
                obsname.append(t[0])
                kk = int(t[1])
                ii = int(t[2])
                jj = int(t[3])
                obslrc.append([kk, ii, jj])
                nobs = len(obsname)

        # create swi2 instance
        swi2 = ModflowSwi2(model, nsrf=nsrf, istrat=istrat, nobs=nobs, iswizt=iswizt, ipakcb=ipakcb,
                           iswiobs=iswiobs, options=options,
                           nsolver=nsolver, iprsol=iprsol, mutsol=mutsol, solver2params=solver2params,
                           toeslope=toeslope, tipslope=tipslope, alpha=alpha, beta=beta,
                           nadptmx=nadptmx, nadptmn=nadptmn, adptfct=adptfct,
                           nu=nu, zeta=zeta, ssz=ssz, isource=isource,
                           obsnam=obsname, obslrc=obslrc)

        # return swi2 instance
        return swi2
Пример #15
0
    def load(f, model, nlay=None, nrow=None, ncol=None, nper=None,
             ncomp=None, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.mt3d.mt.Mt3dms`) to
            which this package will be added.
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        uzt :  Mt3dSsm object
            Mt3dUzt object.

        Examples
        --------

        >>> import flopy
        >>> mt = flopy.mt3d.Mt3dms()
        >>> uzt = flopy.mt3d.Mt3dUzt.load('test.uzt', mt)

        """

        if model.verbose:
            print('loading uzt package file...\n')

        # Open file if necessary
        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')

        # Set dimensions if necessary
        if nlay is None:
            nlay = model.nlay
        if nrow is None:
            nrow = model.nrow
        if ncol is None:
            ncol = model.ncol
        if nper is None:
            nper = model.nper
        if ncomp is None:
            ncomp = model.ncomp

        # Item 1 (comments, must be preceded by '#')
        if model.verbose:
            print('   Reading off comment lines...')
        line = f.readline()
        while line[0:1] == '#':
            i = 1
            if model.verbose:
                print('   Comment Line ' + str(i) + ': '.format(line.strip()))
                i += 1
            line = f.readline()

        # Item 2 (MXUZCON, ICBCUZ, IET)
        if line[0:1] != '#':
            # Don't yet read the next line because the current line because it
            # contains the values in item 2
            m_arr = line.strip().split()
            mxuzcon = int(m_arr[0])
            icbcuz = int(m_arr[1])
            iet = int(m_arr[2])

        # Item 3 [IUZFBND(NROW,NCOL) (one array for each layer)]
        if model.verbose:
            print('   loading IUZFBND...')
        iuzfbnd = Util2d.load(f, model, (nrow, ncol), np.int, 'iuzfbnd',
                              ext_unit_dict)

        # Item 4 [WC(NROW,NCOL) (one array for each layer)]
        if model.verbose:
            print('   loading WC...')
        wc = Util3d.load(f, model, (nlay, nrow, ncol), np.float32, 'wc',
                         ext_unit_dict)

        # Item 5 [SDH(NROW,NCOL) (one array for each layer)]
        if model.verbose:
            print('   loading SDH...')
        sdh = Util3d.load(f, model, (nlay, nrow, ncol), np.float32, 'sdh',
                          ext_unit_dict)

        # kwargs needed to construct cuzinf2, cuzinf3, etc. for multispecies
        kwargs = {}

        cuzinf = None
        # At least one species being simulated, so set up a place holder
        t2d = Transient2d(model, (nrow, ncol), np.float32, 0.0, name='cuzinf',
                          locat=0)
        cuzinf = {0 : t2d}
        if ncomp > 1:
            for icomp in range(2, ncomp + 1):
                name = 'cuzinf' + str(icomp)
                t2d = Transient2d(model, (nrow, ncol), np.float32, 0.0,
                                  name=name, locat=0)
                kwargs[name] = {0 : t2d}

        # Repeat cuzinf initialization procedure for cuzet only if iet != 0
        if iet != 0:
            cuzet = None
            t2d = Transient2d(model, (nrow, ncol), np.float32, 0.0, name='cuzet',
                              locat=0)
            cuzet = {0 : t2d}
            if ncomp > 1:
                for icomp in range(2, ncomp + 1):
                    name = 'cuzet' + str(icomp)
                    t2d = Transient2d(model, (nrow, ncol), np.float32, 0.0,
                                      name=name, locat=0)
                    kwargs[name] = {0 : t2d}

            # Repeat cuzinf initialization procedures for cgwet
            cgwet = None
            t2d = Transient2d(model, (nrow, ncol), np.float32, 0.0, name='cgwet',
                              locat=0)
            cgwet = {0 : t2d}
            if ncomp > 1:
                for icomp in range(2, ncomp + 1):
                    name = 'cgwet' + str(icomp)
                    t2d = Transient2d(model, (nrow, ncol), np.float32, 0.0,
                                      name=name, locat=0)
                    kwargs[name] = {0 : t2d}
        elif iet == 0:
            cuzet = None
            cgwet = None

        # Start of transient data
        for iper in range(nper):

            if model.verbose:
                print('   loading UZT data for kper {0:5d}'.format(iper + 1))

            # Item 6 (INCUZINF)
            line = f.readline()
            m_arr = line.strip().split()
            incuzinf = int(m_arr[0])

            # Item 7 (CUZINF)
            if incuzinf >= 0:
                if model.verbose:
                    print('   Reading CUZINF array for kper ' \
                          '{0:5d}'.format(iper + 1))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'cuzinf',
                                ext_unit_dict)
                cuzinf[iper] = t

                # Load each multispecies array
                if ncomp > 1:
                    for icomp in range(2, ncomp + 1):
                        name = 'cuzinf' + str(icomp)
                        if model.verbose:
                            print('   loading {}...'.format(name))
                        t = Util2d.load(f, model, (nrow, ncol), np.float32,
                                        name, ext_unit_dict)
                        cuzinficomp = kwargs[name]
                        cuzinficomp[iper] = t

            elif incuzinf < 0 and iper == 0:
                if model.verbose:
                    print('   INCUZINF < 0 in first stress period. Setting ' \
                          'CUZINF to default value of 0.00 for all calls')
                    # This happens implicitly and is taken care of my
                    # existing functionality within flopy.  This elif
                    # statement exist for the purpose of printing the message
                    # above
                pass

            elif incuzinf < 0 and iper > 0:
                if model.verbose:
                    print('   Reusing CUZINF array from kper ' \
                          '{0:5d}'.format(iper) + ' in kper ' \
                          '{0:5d}'.format(iper + 1))

            if iet != 0:
                # Item 8 (INCUZET)
                line = f.readline()
                m_arr = line.strip().split()
                incuzet = int(m_arr[0])

                # Item 9 (CUZET)
                if incuzet >= 0:
                    if model.verbose:
                        print('   Reading CUZET array for kper ' \
                              '{0:5d}'.format(iper + 1))
                    t = Util2d.load(f, model, (nrow, ncol), np.float32, 'cuzet',
                                    ext_unit_dict)
                    cuzet[iper] = t

                    # Load each multispecies array
                    if ncomp > 1:
                        for icomp in range(2, ncomp + 1):
                            name = 'cuzet' + str(icomp)
                            if model.verbose:
                                print('   loading {}'.format(name))
                            t = Util2d.load(f, model, (nrow, ncol), np.float32,
                                            name, ext_unit_dict)
                            cuzeticomp = kwargs[name]
                            cuzeticomp[iper] = t

                elif incuzet < 0 and iper == 0:
                    if model.verbose:
                        print('   INCUZET < 0 in first stress period. Setting ' \
                              'CUZET to default value of 0.00 for all calls')
                        # This happens implicitly and is taken care of my
                        # existing functionality within flopy.  This elif
                        # statement exist for the purpose of printing the message
                        # above
                    pass
                else:
                    if model.verbose:
                        print('   Reusing CUZET array from kper ' \
                              '{0:5d}'.format(iper) + ' in kper ' \
                              '{0:5d}'.format(iper + 1))

                # Item 10 (INCGWET)
                line = f.readline()
                m_arr = line.strip().split()
                incgwet = int(m_arr[0])

                # Item 11 (CGWET)
                if model.verbose:
                    if incuzet >= 0:
                        print('   Reading CGWET array for kper ' \
                              '{0:5d}'.format(iper + 1))
                    t = Util2d.load(f, model, (nrow,ncol), np.float32, 'cgwet',
                                    ext_unit_dict)
                    cgwet[iper] = t

                    # Load each multispecies array
                    if ncomp > 1:
                        for icomp in range(2, ncomp + 1):
                            name = 'cgwet' + str(icomp)
                            if model.verbose:
                                print('   loading {}...'.format(name))
                            t = Util2d.load(f, model, (nrow, ncol), np.float32,
                                            name, ext_unit_dict)
                            cgweticomp = kwargs[name]
                            cgweticomp[iper] = t

                elif incuzet < 0 and iper == 0:
                    if model.verbose:
                        print('   INCGWET < 0 in first stress period. Setting ' \
                              'CGWET to default value of 0.00 for all calls')
                        # This happens implicitly and is taken care of my
                        # existing functionality within flopy.  This elif
                        # statement exist for the purpose of printing the
                        # message above
                        pass

                elif incgwet < 0 and iper > 0:
                    if model.verbose:
                        print('   Reusing CGWET array from kper ' \
                              '{0:5d}'.format(iper) + ' in kper ' \
                              '{0:5d}'.format(iper + 1))

        # Construct and return uzt package
        uzt = Mt3dUzt(model, mxuzcon=mxuzcon, icbcuz=icbcuz, iet=iet,
                      iuzfbnd=iuzfbnd, wc=wc, sdh=sdh, cuzinf=cuzinf,
                      cuzet=cuzet, cgwet=cgwet, **kwargs)
        return uzt
Пример #16
0
    def load(f, model, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.modflow.mf.Modflow`) to
            which this package will be added.
        nper : int
            The number of stress periods.  If nper is None, then nper will be
            obtained from the model object. (default is None).
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        wel : ModflowBcf object
            ModflowBcf object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> wel = flopy.modflow.ModflowBcf.load('test.bcf', m)

        """

        if model.verbose:
            sys.stdout.write('loading bcf package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        # Item 1: ipakcb, HDRY, IWDFLG, WETFCT, IWETIT, IHDWET - line already read above
        if model.verbose:
            print('   loading ipakcb, HDRY, IWDFLG, WETFCT, IWETIT, IHDWET...')
        t = line.strip().split()
        ipakcb, hdry, iwdflg, wetfct, iwetit, ihdwet = int(t[0]), float(t[1]), int(t[2]), \
                                                       float(t[3]), int(t[4]), int(t[5])
        if ipakcb != 0:
            model.add_pop_key_list(ipakcb)
            ipakcb = 53
        # LAYCON array
        if model.verbose:
            print('   loading LAYCON...')
        line = f.readline()
        t = line.strip().split()
        intercellt = np.zeros(nlay, dtype=np.int)
        laycon = np.zeros(nlay, dtype=np.int)
        for k in range(nlay):
            ival = int(t[k])
            if ival > 9:
                intercellt[k] = int(t[k][0])
                laycon[k] = int(t[k][1])
            else:
                laycon[k] = ival
        # TRPY array
        if model.verbose:
            print('   loading TRPY...')
        trpy = Util2d.load(f, model, (1, nlay), np.float32, 'trpy', ext_unit_dict)
        trpy = trpy.array.reshape((nlay))
        # property data for each layer based on options
        transient = not model.get_package('DIS').steady.all()
        sf1 = np.empty((nlay, nrow, ncol), dtype=np.float)
        tran = np.empty((nlay, nrow, ncol), dtype=np.float)
        hy = np.empty((nlay, nrow, ncol), dtype=np.float)
        if nlay > 1:
            vcont = np.empty((nlay - 1, nrow, ncol), dtype=np.float)
        else:
            vcont = 1.0
        sf2 = np.empty((nlay, nrow, ncol), dtype=np.float)
        wetdry = np.empty((nlay, nrow, ncol), dtype=np.float)
        for k in range(nlay):
            if transient == True:
                if model.verbose:
                    print('   loading sf1 layer {0:3d}...'.format(k + 1))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'sf1', ext_unit_dict)
                sf1[k, :, :] = t.array
            if ((laycon[k] == 0) or (laycon[k] == 2)):
                if model.verbose:
                    print('   loading tran layer {0:3d}...'.format(k + 1))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'tran', ext_unit_dict)
                tran[k, :, :] = t.array
            else:
                if model.verbose:
                    print('   loading hy layer {0:3d}...'.format(k + 1))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'hy', ext_unit_dict)
                hy[k, :, :] = t.array
            if k < (nlay - 1):
                if model.verbose:
                    print('   loading vcont layer {0:3d}...'.format(k + 1))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'vcont', ext_unit_dict)
                vcont[k, :, :] = t.array
            if ((transient == True) and ((laycon[k] == 2) or (laycon[k] == 3))):
                if model.verbose:
                    print('   loading sf2 layer {0:3d}...'.format(k + 1))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'sf2', ext_unit_dict)
                sf2[k, :, :] = t.array
            if ((iwdflg != 0) and ((laycon[k] == 1) or (laycon[k] == 3))):
                if model.verbose:
                    print('   loading sf2 layer {0:3d}...'.format(k + 1))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'wetdry', ext_unit_dict)
                wetdry[k, :, :] = t.array

        # create instance of bcf object
        bcf = ModflowBcf(model, ipakcb=ipakcb, intercellt=intercellt, laycon=laycon, trpy=trpy, hdry=hdry,
                         iwdflg=iwdflg, wetfct=wetfct, iwetit=iwetit, ihdwet=ihdwet,
                         tran=tran, hy=hy, vcont=vcont, sf1=sf1, sf2=sf2, wetdry=wetdry)

        # return bcf object
        return bcf
Пример #17
0
    def load(f, model, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.modflow.mf.Modflow`) to
            which this package will be added.
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        sub : ModflowSub object

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> sub = flopy.modflow.ModflowSub.load('test.sub', m)

        """

        if model.verbose:
            sys.stdout.write('loading sub package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()

        # read dataset 1
        if model.verbose:
            sys.stdout.write('  loading sub dataset 1\n')
        t = line.strip().split()
        ipakcb, isuboc, nndb, ndb, nmz, nn = int(t[0]), int(t[1]), int(t[2]), int(t[3]), int(t[4]), int(t[5])
        ac1, ac2 = float(t[6]), float(t[7])
        itmin, idsave, idrest = int(t[8]), int(t[9]), int(t[10])

        if ipakcb > 0:
            ipakcb = 53
        if idsave > 0:
            idsave = 2052
        if idrest > 0:
            ext_unit_dict[2053] = ext_unit_dict.pop(idrest)
            idrest = 2053

        ln = None
        if nndb > 0:
            if model.verbose:
                sys.stdout.write('  loading sub dataset 2\n')
            ln = np.empty((nndb), dtype=np.int)
            ln = read1d(f, ln) - 1
        ldn = None
        if ndb > 0:
            if model.verbose:
                sys.stdout.write('  loading sub dataset 3\n')
            ldn = np.empty((ndb), dtype=np.int)
            ldn = read1d(f, ldn) - 1
        rnb = None
        if ndb > 0:
            if model.verbose:
                sys.stdout.write('  loading sub dataset 4\n')
            rnb = [0] * ndb
            for k in range(ndb):
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'rnb delay bed {}'.format(k + 1),
                                 ext_unit_dict)
                rnb[k] = t
        hc = None
        sfe = None
        sfv = None
        com = None
        if nndb > 0:
            hc = [0] * nndb
            sfe = [0] * nndb
            sfv = [0] * nndb
            com = [0] * nndb
            for k in range(nndb):
                kk = ln[k] + 1
                # hc
                if model.verbose:
                    sys.stdout.write('  loading sub dataset 5 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'hc layer {}'.format(kk),
                                 ext_unit_dict)
                hc[k] = t
                # sfe
                if model.verbose:
                    sys.stdout.write('  loading sub dataset 6 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'sfe layer {}'.format(kk),
                                 ext_unit_dict)
                sfe[k] = t
                # sfv
                if model.verbose:
                    sys.stdout.write('  loading sub dataset 7 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'sfv layer {}'.format(kk),
                                 ext_unit_dict)
                sfv[k] = t
                # com
                if model.verbose:
                    sys.stdout.write('  loading sub dataset 8 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'com layer {}'.format(kk),
                                 ext_unit_dict)
                com[k] = t

        # dp
        dp = None
        if ndb > 0:
            dp = np.zeros((nmz, 3), dtype=np.float32)
            for k in range(nmz):
                if model.verbose:
                    sys.stdout.write('  loading sub dataset 9 for material zone {}\n'.format(k + 1))
                line = f.readline()
                t = line.strip().split()
                dp[k, :] = float(t[0]), float(t[1]), float(t[2])

        dstart = None
        dhc = None
        dcom = None
        dz = None
        nz = None
        if ndb > 0:
            dstart = [0] * ndb
            dhc = [0] * ndb
            dcom = [0] * ndb
            dz = [0] * ndb
            nz = [0] * ndb
            for k in range(ndb):
                kk = ldn[k] + 1
                # dstart
                if model.verbose:
                    sys.stdout.write('  loading sub dataset 10 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'dstart layer {}'.format(kk),
                                 ext_unit_dict)
                dstart[k] = t
                # dhc
                if model.verbose:
                    sys.stdout.write('  loading sub dataset 11 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'dhc layer {}'.format(kk),
                                 ext_unit_dict)
                dhc[k] = t
                # dcom
                if model.verbose:
                    sys.stdout.write('  loading sub dataset 12 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'dcom layer {}'.format(kk),
                                 ext_unit_dict)
                dcom[k] = t
                # dz
                if model.verbose:
                    sys.stdout.write('  loading sub dataset 13 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'dz layer {}'.format(kk),
                                 ext_unit_dict)
                dz[k] = t
                # nz
                if model.verbose:
                    sys.stdout.write('  loading sub dataset 14 for layer {}\n'.format(kk))
                t = Util2d.load(f, model, (nrow, ncol), np.int, 'nz layer {}'.format(kk),
                                 ext_unit_dict)
                nz[k] = t

        ids15 = None
        ids16 = None
        if isuboc > 0:
            # dataset 15
            if model.verbose:
                sys.stdout.write('  loading sub dataset 15 for layer {}\n'.format(kk))
            ids15 = np.empty(12, dtype=np.int)
            ids15 = read1d(f, ids15)
            for k in range(1, 12, 2):
                model.add_pop_key_list(ids15[k])
                ids15[k] = 2051  # all subsidence data sent to unit 2051
            # dataset 16
            ids16 = [0] * isuboc
            for k in range(isuboc):
                if model.verbose:
                    sys.stdout.write('  loading sub dataset 16 for isuboc {}\n'.format(k + 1))
                t = np.empty(17, dtype=np.int)
                t = read1d(f, t)
                t[0:4] -= 1
                ids16[k] = t

        # close file
        f.close()

        # create sub instance
        sub = ModflowSub(model, ipakcb=ipakcb, isuboc=isuboc, idsave=idsave, idrest=idrest,
                         nndb=nndb, ndb=ndb, nmz=nmz, nn=nn, ac1=ac1, ac2=ac2, itmin=itmin,
                         ln=ln, ldn=ldn, rnb=rnb,
                         hc=hc, sfe=sfe, sfv=sfv, com=com, dp=dp,
                         dstart=dstart, dhc=dhc, dcom=dcom, dz=dz, nz=nz,
                         ids15=ids15, ids16=ids16)
        # return sub instance
        return sub
Пример #18
0
    def load(f, nrow, ncol, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        nrow : int
            number of rows.
        ncol : int
            number of columns.
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        zone : ModflowMult dict

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> mlt = flopy.modflow.ModflowMlt.load('test.mlt', m)

        """
        import flopy as fp

        model = fp.modflow.Modflow("imadummy")

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- __header
        while True:
            line = f.readline()
            if line[0] != '#':
                break

        # dataset 1
        t = line.strip().split()
        nml = int(t[0])

        # read zone data
        mult_dict = collections.OrderedDict()
        mult_equations = collections.OrderedDict()
        for n in range(nml):
            line = f.readline()
            while True:
                if line.strip().startswith("#"):
                    line = f.readline()
                else:
                    break
            print("Reading : {}".format(line.strip().split()[0]))
            t = line.strip().split()
            if len(t[0]) > 10:
                mltnam = t[0][0:10].lower()
            else:
                mltnam = t[0].lower()

            readArray = True
            kwrd = None
            if len(t) > 1:
                if 'function' in t[1].lower() or 'expression' in t[1].lower():
                    readArray = False
                    kwrd = t[1].lower()
            # load data
            if readArray:
                t = Util2d.load(f, model, (nrow, ncol), np.float32, mltnam,
                                ext_unit_dict)

            else:
                line = f.readline().rstrip()
                t = [kwrd, line]
                if kwrd == 'function':
                    parser = FunctionParser(line, mult_dict)
                elif kwrd == 'expression':
                    parser = ExpressionParser(line, mult_dict)
                else:
                    raise TypeError(
                        '{}: not a Function or Expression'.format(kwrd))
                mult_equations[mltnam] = {'keyword': kwrd, 'equation': line}

                t = Util2d(model, parser.result.shape, np.float32,
                           parser.result, mltnam)

            mult_dict[mltnam] = t

        # create mlt dictionary
        mlt = ModflowMlt(mult_dict=mult_dict, mult_equations=mult_equations)

        return mlt
Пример #19
0
    def load(f, model, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.modflow.mf.Modflow`) to
            which this package will be added.
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        lpf : ModflowLpf object
            ModflowLpf object.

        Examples
        --------

        >>> import flopy
        >>> m = flopy.modflow.Modflow()
        >>> lpf = flopy.modflow.ModflowLpf.load('test.lpf', m)

        """

        if model.verbose:
            sys.stdout.write('loading lpf package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')
        # dataset 0 -- header
        while True:
            line = f.readline()
            if line[0] != '#':
                break
        # determine problem dimensions
        nrow, ncol, nlay, nper = model.get_nrow_ncol_nlay_nper()
        # Item 1: IBCFCB, HDRY, NPLPF - line already read above
        if model.verbose:
            print('   loading IBCFCB, HDRY, NPLPF...')
        t = line.strip().split()
        ipakcb, hdry, nplpf = int(t[0]), float(t[1]), int(t[2])
        if ipakcb != 0:
            model.add_pop_key_list(ipakcb)
            ipakcb = 53
        # options
        storagecoefficient = False
        constantcv = False
        thickstrt = False
        nocvcorrection = False
        novfc = False
        if len(t) > 3:
            for k in range(3, len(t)):
                if 'STORAGECOEFFICIENT' in t[k].upper():
                    storagecoefficient = True
                elif 'CONSTANTCV' in t[k].upper():
                    constantcv = True
                elif 'THICKSTRT' in t[k].upper():
                    thickstrt = True
                elif 'NOCVCORRECTION' in t[k].upper():
                    nocvcorrection = True
                elif 'NOVFC' in t[k].upper():
                    novfc = True
        # LAYTYP array
        if model.verbose:
            print('   loading LAYTYP...')
        laytyp = np.empty((nlay), dtype=np.int)
        laytyp = read1d(f, laytyp)
        # LAYAVG array
        if model.verbose:
            print('   loading LAYAVG...')
        layavg = np.empty((nlay), dtype=np.int)
        layavg = read1d(f, layavg)
        # CHANI array
        if model.verbose:
            print('   loading CHANI...')
        chani = np.empty((nlay), dtype=np.float32)
        chani = read1d(f, chani)
        # LAYVKA array
        if model.verbose:
            print('   loading LAYVKA...')
        layvka = np.empty((nlay), dtype=np.float32)
        layvka = read1d(f, layvka)
        # LAYWET array
        if model.verbose:
            print('   loading LAYWET...')
        laywet = np.empty((nlay), dtype=np.int)
        laywet = read1d(f, laywet)
        # Item 7: WETFCT, IWETIT, IHDWET
        wetfct, iwetit, ihdwet = None, None, None
        iwetdry = laywet.sum()
        if iwetdry > 0:
            if model.verbose:
                print('   loading WETFCT, IWETIT, IHDWET...')
            line = f.readline()
            t = line.strip().split()
            wetfct, iwetit, ihdwet = float(t[0]), int(t[1]), int(t[2])

        # parameters data
        par_types = []
        if nplpf > 0:
            par_types, parm_dict = mfpar.load(f, nplpf, model.verbose)
            #print parm_dict

        # non-parameter data
        transient = not model.get_package('DIS').steady.all()
        hk = [0] * nlay
        hani = [0] * nlay
        vka = [0] * nlay
        ss = [0] * nlay
        sy = [0] * nlay
        vkcb = [0] * nlay
        wetdry = [0] * nlay
        for k in range(nlay):
            if model.verbose:
                print('   loading hk layer {0:3d}...'.format(k + 1))
            if 'hk' not in par_types:
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'hk',
                                 ext_unit_dict)
            else:
                line = f.readline()
                t = mfpar.parameter_fill(model, (nrow, ncol), 'hk', parm_dict, findlayer=k)
            hk[k] = t
            if chani[k] < 0:
                if model.verbose:
                    print('   loading hani layer {0:3d}...'.format(k + 1))
                if 'hani' not in par_types:
                    t = Util2d.load(f, model, (nrow, ncol), np.float32, 'hani',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'hani', parm_dict, findlayer=k)
                hani[k] = t
            if model.verbose:
                print('   loading vka layer {0:3d}...'.format(k + 1))
            key = 'vka'
            if layvka[k] != 0:
                key = 'vani'
            if 'vka' not in par_types and 'vani' not in par_types:
                t = Util2d.load(f, model, (nrow, ncol), np.float32, key,
                                 ext_unit_dict)
            else:
                line = f.readline()
                key = 'vka'
                if 'vani' in par_types:
                    key = 'vani'
                t = mfpar.parameter_fill(model, (nrow, ncol), key, parm_dict, findlayer=k)
            vka[k] = t
            if transient:
                if model.verbose:
                    print('   loading ss layer {0:3d}...'.format(k + 1))
                if 'ss' not in par_types:
                    t = Util2d.load(f, model, (nrow, ncol), np.float32, 'ss',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'ss', parm_dict, findlayer=k)
                ss[k] = t
                if laytyp[k] != 0:
                    if model.verbose:
                        print('   loading sy layer {0:3d}...'.format(k + 1))
                    if 'sy' not in par_types:
                        t = Util2d.load(f, model, (nrow, ncol), np.float32, 'sy',
                                         ext_unit_dict)
                    else:
                        line = f.readline()
                        t = mfpar.parameter_fill(model, (nrow, ncol), 'sy', parm_dict, findlayer=k)
                    sy[k] = t
            #if self.parent.get_package('DIS').laycbd[k] > 0:
            if model.get_package('DIS').laycbd[k] > 0:
                if model.verbose:
                    print('   loading vkcb layer {0:3d}...'.format(k + 1))
                if 'vkcb' not in par_types:
                    t = Util2d.load(f, model, (nrow, ncol), np.float32, 'vkcb',
                                     ext_unit_dict)
                else:
                    line = f.readline()
                    t = mfpar.parameter_fill(model, (nrow, ncol), 'vkcb', parm_dict, findlayer=k)
                vkcb[k] = t
            if (laywet[k] != 0 and laytyp[k] != 0):
                if model.verbose:
                    print('   loading wetdry layer {0:3d}...'.format(k + 1))
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'wetdry',
                                 ext_unit_dict)
                wetdry[k] = t

        # create instance of lpf class
        lpf = ModflowLpf(model, ipakcb=ipakcb, laytyp=laytyp, layavg=layavg, chani=chani,
                         layvka=layvka, laywet=laywet, hdry=hdry, iwdflg=iwetdry,
                         wetfct=wetfct, iwetit=iwetit, ihdwet=ihdwet,
                         hk=hk, hani=hani, vka=vka, ss=ss, sy=sy, vkcb=vkcb,
                         wetdry=wetdry, storagecoefficient=storagecoefficient,
                         constantcv=constantcv, thickstrt=thickstrt, novfc=novfc)
        return lpf
Пример #20
0
    def load(f, model, nlay=None, nrow=None, ncol=None, ext_unit_dict=None):
        """
        Load an existing package.

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.mt3d.mt.Mt3dms`) to
            which this package will be added.
        nlay : int
            number of model layers.  If None it will be retrieved from the
            model.
        nrow : int
            number of model rows.  If None it will be retrieved from the
            model.
        ncol : int
            number of model columns.  If None it will be retrieved from the
            model.
        ext_unit_dict : dictionary, optional
            If the arrays in the file are specified using EXTERNAL,
            or older style array control records, then `f` should be a file
            handle.  In this case ext_unit_dict is required, which can be
            constructed using the function
            :class:`flopy.utils.mfreadnam.parsenamefile`.

        Returns
        -------
        adv :  Mt3dDsp object
            Mt3dDsp object.

        Examples
        --------

        >>> import flopy
        >>> mt = flopy.mt3d.Mt3dms()
        >>> dsp = flopy.mt3d.Mt3dAdv.load('test.dsp', m)

        """

        if model.verbose:
            sys.stdout.write("loading dsp package file...\n")

        # Set dimensions if necessary
        if nlay is None:
            nlay = model.nlay
        if nrow is None:
            nrow = model.nrow
        if ncol is None:
            ncol = model.ncol

        # Open file, if necessary
        if not hasattr(f, "read"):
            filename = f
            f = open(filename, "r")

        # Dataset 0 -- comment line
        imsd = 0
        while True:
            line = f.readline()
            if line.strip() == "":
                continue
            elif line[0] == "#":
                continue
            elif line[0] == "$":
                imsd = 1
                break
            else:
                break

        # Check for keywords (multidiffusion)
        multiDiff = False
        if imsd == 1:
            keywords = line[1:].strip().split()
            for k in keywords:
                if k.lower() == "multidiffusion":
                    multiDiff = True
        else:
            # go back to beginning of file
            f.seek(0, 0)

        # Read arrays
        if model.verbose:
            print("   loading AL...")
        al = Util3d.load(f, model, (nlay, nrow, ncol), np.float32, "al", ext_unit_dict)

        if model.verbose:
            print("   loading TRPT...")
        trpt = Util2d.load(f, model, (nlay, 1), np.float32, "trpt", ext_unit_dict)

        if model.verbose:
            print("   loading TRPV...")
        trpv = Util2d.load(f, model, (nlay, 1), np.float32, "trpv", ext_unit_dict)

        if model.verbose:
            print("   loading DMCOEFF...")
        kwargs = {}
        dmcoef = []
        if multiDiff:
            dmcoef = Util3d.load(f, model, (nlay, nrow, ncol), np.float32, "dmcoef1", ext_unit_dict)
            if model.mcomp > 1:
                for icomp in range(2, model.mcomp + 1):
                    name = "dmcoef" + str(icomp)
                    u3d = Util3d.load(f, model, (nlay, nrow, ncol), np.float32, name, ext_unit_dict)
                    kwargs[name] = u3d

        else:
            dmcoef = Util2d.load(f, model, (nlay, 1), np.float32, "dmcoef1", ext_unit_dict)
            if model.mcomp > 1:
                for icomp in range(2, model.mcomp + 1):
                    name = "dmcoef" + str(icomp + 1)
                    u2d = Util2d.load(f, model, (nlay, 1), np.float32, name, ext_unit_dict)
                    kwargs[name] = u2d

        dsp = Mt3dDsp(model, al=al, trpt=trpt, trpv=trpv, dmcoef=dmcoef, multiDiff=multiDiff, **kwargs)
        return dsp
Пример #21
0
    def load(f, model, nlay=1, nrow=1, ncol=1, ext_unit_dict=None):
        """
        Load an existing package

        Parameters
        ----------
        f : filename or file handle
            File to load.
        model : model object
            The model object (of type :class:`flopy.modflow.mf.Modflow`) to
            which this package will be added.
        nlay : int
            number of model layers
        nrow : int
            number of model rows
        ncol : int
            number of model columns
        ext_unit_dict : dict
            Dictionary of unit and file names

        Returns
        -------
        bcf : Modflow88Bas object
            Modflow88Bcf object (of type :class:`mf2web.mf88.Modflow88Bcf`)
        """

        if model.verbose:
            sys.stdout.write('loading bas6 package file...\n')

        if not hasattr(f, 'read'):
            filename = f
            f = open(filename, 'r')

        if model.nrow_ncol_nlay_nper != (0, 0, 0, 0):
            nrow, ncol, nlay, nper = model.nrow_ncol_nlay_nper

        iss, ibcfcb = [int(i) for i in f.readline()[0:20].split()]

        line = f.readline()
        t = []
        istart = 0
        for k in range(nlay):
            lcode = line[istart:istart + 2]
            lcode = lcode.replace(' ', '0')
            t.append(lcode)
            istart += 2
        laycon = np.zeros(nlay, dtype=np.int32)
        for k in range(nlay):
            laycon[k] = int(t[k][1])

        trpy = Util2d.load(f, model, (nlay, ), np.float32, 'trpy',
                           ext_unit_dict)

        delr = Util2d.load(f, model, (ncol, ), np.float32, 'delr',
                           ext_unit_dict)

        delc = Util2d.load(f, model, (nrow, ), np.float32, 'delc',
                           ext_unit_dict)

        sf1 = np.zeros((nlay, nrow, ncol))
        tran = np.zeros((nlay, nrow, ncol))
        hy = np.zeros((nlay, nrow, ncol))
        bot = np.zeros((nlay, nrow, ncol))
        top = np.zeros((nlay, nrow, ncol))

        if nlay > 1:
            vcont = np.zeros((nlay - 1, nrow, ncol))
        else:
            vcont = np.zeros((nlay, nrow, ncol))

        sf2 = np.zeros((nlay, nrow, ncol))

        for k in range(nlay):

            # sf1
            if iss != 0:
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'sf1',
                                ext_unit_dict)
                sf1[k] = t.array

            # tran or hy and bot
            if ((laycon[k] == 0) or (laycon[k] == 2)):
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'tran',
                                ext_unit_dict)
                tran[k] = t.array
            else:
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'hy',
                                ext_unit_dict)
                hy[k] = t.array

                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'bot',
                                ext_unit_dict)
                bot[k] = t.array

            # vcont
            if k < (nlay - 1):
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'vcont',
                                ext_unit_dict)
                vcont[k] = t.array

            # sf2
            if (iss != 0 and ((laycon[k] == 2) or (laycon[k] == 3))):
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'sf2',
                                ext_unit_dict)
                sf2[k] = t.array

            if laycon[k] == 2 or laycon[k] == 3:
                t = Util2d.load(f, model, (nrow, ncol), np.float32, 'top',
                                ext_unit_dict)
                top[k] = t.array

        return Modflow88Bcf(model, iss, ibcfcb, laycon, trpy, delr, delc, sf1,
                            tran, hy, bot, vcont, sf2, top)