Example #1
0
def test_mflist_reference():
    import os
    import numpy as np
    import shapefile
    import flopy.modflow as fmf

    # model_ws = os.path.join('..', 'data', 'freyberg')
    # ml = fmf.Modflow.load('freyberg.nam', model_ws=model_ws)
    # make the model
    ml = fmf.Modflow()
    assert isinstance(ml, fmf.Modflow)
    perlen = np.arange(1, 20, 1)
    nstp = np.flipud(perlen) + 3
    tsmult = 1.2
    nlay = 10
    nrow, ncol = 50, 40
    botm = np.arange(0, -100, -10)
    hk = np.random.random((nrow, ncol))
    dis = fmf.ModflowDis(ml,
                         delr=100.0,
                         delc=100.0,
                         nrow=nrow,
                         ncol=ncol,
                         nlay=nlay,
                         nper=perlen.shape[0],
                         perlen=perlen,
                         nstp=nstp,
                         tsmult=tsmult,
                         top=10,
                         botm=botm,
                         steady=False)
    assert isinstance(dis, fmf.ModflowDis)
    lpf = fmf.ModflowLpf(ml, hk=hk, vka=10.0, laytyp=1)
    assert isinstance(lpf, fmf.ModflowLpf)
    pcg = fmf.ModflowPcg(ml)
    assert isinstance(pcg, fmf.ModflowPcg)
    oc = fmf.ModflowOc(ml)
    assert isinstance(oc, fmf.ModflowOc)
    ibound = np.ones((nrow, ncol))
    ibound[:, 0] = -1
    ibound[25:30, 30:39] = 0
    bas = fmf.ModflowBas(ml, strt=5.0, ibound=ibound)
    assert isinstance(bas, fmf.ModflowBas)
    rch = fmf.ModflowRch(ml, rech={0: 0.00001, 5: 0.0001, 6: 0.0})
    assert isinstance(rch, fmf.ModflowRch)
    wel_dict = {}
    wel_data = [[9, 25, 20, -200], [0, 0, 0, -400], [5, 20, 32, 500]]
    wel_dict[0] = wel_data
    wel_data2 = [[45, 20, 200], [9, 49, 39, 400], [5, 20, 32, 500]]
    wel_dict[10] = wel_data2
    wel = fmf.ModflowWel(ml, stress_period_data={0: wel_data})
    assert isinstance(wel, fmf.ModflowWel)
    ghb_dict = {0: [1, 10, 10, 400, 300]}
    ghb = fmf.ModflowGhb(ml, stress_period_data=ghb_dict)
    assert isinstance(ghb, fmf.ModflowGhb)

    test = os.path.join('temp', 'test3.shp')
    ml.export(test, kper=0)
    shp = shapefile.Reader(test)
    assert shp.numRecords == nrow * ncol
Example #2
0
 def get_package(self, _mf):
     content = self.merge()
     return mf.ModflowGhb(
         _mf,
         ipakcb=content['ipakcb'],
         stress_period_data=content['stress_period_data'],
         dtype=content['dtype'],
         no_print=content['no_print'],
         options=content['options'],
         extension=content['extension'],
         unitnumber=content['unitnumber']
     )
Example #3
0
    def create_package(self, name, content):
        if name == 'mf':
            model_ws = os.path.realpath(os.path.join(self._data_folder, self._model_id, content['model_ws']))
            if not os.path.exists(model_ws):
                os.makedirs(model_ws)

            self._mf = mf.Modflow(
                modelname=content['modelname'],
                exe_name=content['exe_name'],
                version=content['version'],
                model_ws=model_ws
            )
        if name == 'dis':
            mf.ModflowDis(
                self._mf,
                nlay=content['nlay'],
                nrow=content['nrow'],
                ncol=content['ncol'],
                nper=content['nper'],
                delr=content['delr'],
                delc=content['delc'],
                laycbd=content['laycbd'],
                top=content['top'],
                botm=content['botm'],
                perlen=content['perlen'],
                nstp=content['nstp'],
                tsmult=content['tsmult'],
                steady=content['steady'],
                itmuni=content['itmuni'],
                lenuni=content['lenuni'],
                extension=content['extension'],
                unitnumber=content['unitnumber'],
                xul=content['xul'],
                yul=content['yul'],
                rotation=content['rotation'],
                proj4_str=content['proj4_str'],
                start_datetime=content['start_datetime']
            )
        if name == 'bas':
            mf.ModflowBas(
                self._mf,
                ibound=content['ibound'],
                strt=content['strt'],
                ifrefm=content['ifrefm'],
                ixsec=content['ixsec'],
                ichflg=content['ichflg'],
                stoper=content['stoper'],
                hnoflo=content['hnoflo'],
                extension=content['extension'],
                unitnumber=content['unitnumber']
            )
        if name == 'lpf':
            mf.ModflowLpf(
                self._mf,
                laytyp=content['laytyp'],
                layavg=content['layavg'],
                chani=content['chani'],
                layvka=content['layvka'],
                laywet=content['laywet'],
                ipakcb=content['ipakcb'],
                hdry=content['hdry'],
                iwdflg=content['iwdflg'],
                wetfct=content['wetfct'],
                iwetit=content['iwetit'],
                ihdwet=content['ihdwet'],
                hk=content['hk'],
                hani=content['hani'],
                vka=content['vka'],
                ss=content['ss'],
                sy=content['sy'],
                vkcb=content['vkcb'],
                wetdry=content['wetdry'],
                storagecoefficient=content['storagecoefficient'],
                constantcv=content['constantcv'],
                thickstrt=content['thickstrt'],
                nocvcorrection=content['nocvcorrection'],
                novfc=content['novfc'],
                extension=content['extension'],
                unitnumber=content['unitnumber']
            )
        if name == 'pcg':
            mf.ModflowPcg(
                self._mf,
                mxiter=content['mxiter'],
                iter1=content['iter1'],
                npcond=content['npcond'],
                hclose=content['hclose'],
                rclose=content['rclose'],
                relax=content['relax'],
                nbpol=content['nbpol'],
                iprpcg=content['iprpcg'],
                mutpcg=content['mutpcg'],
                damp=content['damp'],
                dampt=content['dampt'],
                ihcofadd=content['ihcofadd'],
                extension=content['extension'],
                unitnumber=content['unitnumber']
            )
        if name == 'oc':
            mf.ModflowOc(
                self._mf,
                ihedfm=content['ihedfm'],
                iddnfm=content['iddnfm'],
                chedfm=content['chedfm'],
                cddnfm=content['cddnfm'],
                cboufm=content['cboufm'],
                compact=content['compact'],
                stress_period_data=self.get_stress_period_data(content['stress_period_data']),
                extension=content['extension'],
                unitnumber=content['unitnumber']
            )
        if name == 'risdlkfjlv':
            mf.ModflowRiv(
                self._mf,
                ipakcb=content['ipakcb'],
                stress_period_data=content['stress_period_data'],
                dtype=content['dtype'],
                extension=content['extension'],
                unitnumber=content['unitnumber'],
                options=content['options'],
                naux=content['naux']
            )
        if name == 'wel':
            mf.ModflowWel(
                self._mf,
                ipakcb=content['ipakcb'],
                stress_period_data=content['stress_period_data'],
                dtype=content['dtype'],
                extension=content['extension'],
                unitnumber=content['unitnumber'],
                options=content['options']
            )
        if name == 'rch':
            mf.ModflowRch(
                self._mf,
                ipakcb=content['ipakcb'],
                nrchop=content['nrchop'],
                rech=content['rech'],
                extension=content['extension'],
                unitnumber=content['unitnumber']
            )
        if name == 'chd':
            mf.ModflowChd(
                self._mf,
                stress_period_data=content['stress_period_data'],
                dtype=content['dtype'],
                options=content['options'],
                extension=content['extension'],
                unitnumber=content['unitnumber']
            )

        if name == 'ghb':
            mf.ModflowGhb(
                self._mf,
                ipakcb=content['ipakcb'],
                stress_period_data=content['stress_period_data'],
                dtype=content['dtype'],
                options=content['options'],
                extension=content['extension'],
                unitnumber=content['unitnumber']
            )
Example #4
0
                        nlay=3,
                        delr=delr,
                        delc=delc,
                        laycbd=[0, 0, 0],
                        top=-9.0,
                        botm=[-29, -30, -50],
                        nper=2,
                        perlen=[365 * 1000, 1000 * 365],
                        nstp=[500, 500])
bas = mf.ModflowBas(ml, ibound=1, strt=1.0)
bcf = mf.ModflowBcf(ml,
                    laycon=[0, 0, 0],
                    tran=[40.0, 1, 80.0],
                    vcont=[0.005, 0.005])
wel = mf.ModflowWel(ml, stress_period_data={0: lrcQ1, 1: lrcQ2})
ghb = mf.ModflowGhb(ml, stress_period_data={0: lrchc})
swi = mf.ModflowSwi2(ml,
                     nsrf=1,
                     istrat=1,
                     toeslope=0.01,
                     tipslope=0.04,
                     nu=[0, 0.025],
                     zeta=[zini, zini, zini],
                     ssz=0.2,
                     isource=iso,
                     nsolver=1)
oc = mf.ModflowOc(ml, save_head_every=100)
pcg = mf.ModflowPcg(ml)
#--write the model files
ml.write_input()
#--run the model
Example #5
0
bas = mf.ModflowBas(ml, ibound=iBound, strt=start)

# set the aquifer properties with the lpf-package
lpf = mf.ModflowLpf(ml, hk=k)

# GHB For stress period data we define LAY/ROW/COL/STAGE/COND

gh = int(sys.argv[1])

if gh == 1:
    lrgh = [[0, 0, 9, 90, 100], [0, 1, 9, 90, 100], [0, 2, 9, 90, 100],
            [0, 3, 9, 90, 100], [0, 4, 9, 90, 100], [0, 5, 9, 90, 100],
            [0, 6, 9, 90, 100], [0, 7, 9, 90, 100], [0, 8, 9, 90, 100],
            [0, 9, 9, 90, 100]]

    ghb = mf.ModflowGhb(ml, stress_period_data=lrgh)

    # instantiation of the solver with default values
    pcg = mf.ModflowPcg(ml)

    # instantiation of the output control with default values
    oc = mf.ModflowOc(ml)

    timeStartWritingInput = datetime.now()
    ml.write_input()
    timeStartRunningModel = datetime.now()
    ml.run_model()
    timeEndRunningModel = datetime.now()
    print "Time writing input: " + str(timeStartRunningModel -
                                       timeStartWritingInput)
    print "Calculation Time: " + str(timeEndRunningModel -
Example #6
0
 def get_package(self, _mf):
     content = self.merge()
     return mf.ModflowGhb(_mf, **content)
Example #7
0
def calculate_model(z1_hk, z2_hk, z3_hk):
    # Z1_hk = 15  # 3<Z1_hk<15
    # Z2_hk = 15  # 3<Z2_hk<15
    # Z3_hk = 3  # 3<Z3_hk<15

    hobs = [
        [0, 20, 10, 69.52],
        [0, 40, 10, 71.44],
        [0, 60, 10, 72.99],
        [0, 80, 10, 73.86],
        [0, 20, 45, 58.73],
        [0, 40, 45, 50.57],
        [0, 60, 45, 54.31],
        [0, 80, 45, 58.06],
        [0, 20, 80, 56.31],
        [0, 40, 80, 52.32],
        [0, 60, 80, 46.35],
        [0, 80, 80, 29.01],
        [0, 20, 100, 57.24],
        [0, 40, 100, 54.24],
        [0, 60, 100, 39.48],
        [0, 80, 100, 48.47],
    ]

    model_path = os.path.join('_model')

    if os.path.exists(model_path):
        shutil.rmtree(model_path)

    modelname = 'parEstMod'

    version = 'mf2005'
    exe_name = 'mf2005'
    if platform.system() == 'Windows':
        exe_name = 'mf2005.exe'

    ml = mf.Modflow(modelname=modelname,
                    exe_name=exe_name,
                    version=version,
                    model_ws=model_path)

    nlay = 1
    nrow = 90
    ncol = 120

    area_width_y = 9000
    area_width_x = 12000

    delc = area_width_x / ncol
    delr = area_width_y / nrow

    nper = 1

    top = 100
    botm = 0

    dis = mf.ModflowDis(ml,
                        nlay=nlay,
                        nrow=nrow,
                        ncol=ncol,
                        delr=delr,
                        delc=delc,
                        top=top,
                        botm=botm,
                        nper=nper,
                        steady=True)

    ibound = 1
    strt = 100
    bas = mf.ModflowBas(ml, ibound=ibound, strt=strt)

    mask_arr = np.zeros((nlay, nrow, ncol))
    mask_arr[:, :, 0] = 80
    mask_arr[:, :, -1] = 60

    ghb_spd = {0: []}
    for layer_id in range(nlay):
        for row_id in range(nrow):
            for col_id in range(ncol):
                if mask_arr[layer_id][row_id][col_id] > 0:
                    ghb_spd[0].append([
                        layer_id, row_id, col_id,
                        mask_arr[layer_id][row_id][col_id], 200
                    ])

    ghb = mf.ModflowGhb(ml, stress_period_data=ghb_spd)

    rch = 0.0002
    rech = {}
    rech[0] = rch
    rch = mf.ModflowRch(ml, rech=rech, nrchop=3)

    welSp = {}
    welSp[0] = [
        [0, 20, 20, -20000],
        [0, 40, 40, -20000],
        [0, 60, 60, -20000],
        [0, 80, 80, -20000],
        [0, 60, 100, -20000],
    ]

    wel = mf.ModflowWel(ml, stress_period_data=welSp)

    hk = np.zeros((nlay, nrow, ncol))
    hk[:, :, 0:40] = z1_hk
    hk[:, :, 40:80] = z2_hk
    hk[:, :, 80:120] = z3_hk

    lpf = mf.ModflowLpf(ml, hk=hk, layavg=0, layvka=0, sy=0.3, ipakcb=53)

    pcg = mf.ModflowPcg(ml, rclose=1e-1)
    oc = mf.ModflowOc(ml)

    ml.write_input()
    ml.run_model(silent=True)
    hds = fu.HeadFile(os.path.join(model_path, modelname + '.hds'))
    times = hds.get_times()

    response = []

    for hob in hobs:
        observed = hob[3]
        calculated = hds.get_data(totim=times[-1])[hob[0]][hob[1]][hob[2]]
        response.append(observed - calculated)

    return json.dumps(response)
Example #8
0
                         nlay=nlay,
                         nrow=nrow,
                         ncol=ncol,
                         laycbd=0,
                         delr=delr,
                         delc=delc,
                         top=botm[0],
                         botm=botm[1:],
                         nper=nper,
                         perlen=perlen,
                         nstp=nstp,
                         steady=steady)
 bas = mf.ModflowBas(ml, ibound=ibound, strt=ihead)
 lpf = mf.ModflowLpf(ml, laytyp=laytyp, hk=hk, vka=vka)
 wel = mf.ModflowWel(ml, stress_period_data=base_well_data)
 ghb = mf.ModflowGhb(ml, stress_period_data=ghb_data)
 rch = mf.ModflowRch(ml, rech=rch_data)
 swi = mf.ModflowSwi2(ml,
                      nsrf=1,
                      istrat=1,
                      toeslope=toeslope,
                      tipslope=tipslope,
                      nu=nu,
                      zeta=z,
                      ssz=ssz,
                      isource=iso,
                      nsolver=1,
                      adaptive=adaptive,
                      nadptmx=nadptmx,
                      nadptmn=nadptmn,
                      nobs=nobs,
Example #9
0
dis = fm.ModflowDis(mf,
                    Nlay,
                    Ny,
                    Nx,
                    delr=dx,
                    delc=dy,
                    top=zTop,
                    botm=zBot,
                    laycbd=LAYCBD,
                    nper=NPER,
                    perlen=PERLEN,
                    nstp=NSTP,
                    steady=STEADY)
bas = fm.ModflowBas(mf, ibound=IBOUND, strt=STRTHD)
lpf = fm.ModflowLpf(mf, hk=HK, vka=VKA, sy=SY, ss=SS, laytyp=LAYTYP, vkcb=VKCB)
ghb = fm.ModflowGhb(mf, stress_period_data=GHB)
wel = fm.ModflowWel(mf, stress_period_data=WEL)
rch = fm.ModflowRch(mf, nrchop=3, rech=RECH)
evt = fm.ModflowEvt(mf, nevtop=3, evtr=EVTR)
oc = fm.ModflowOc(mf, stress_period_data=OC, compact=True)
pcg = fm.ModflowPcg(mf)

#%% Write the model input files and running MODFLOW
mf.write_input()

success, mfoutput = mf.run_model(silent=False, pause=False)

print('Running success = {}'.format(success))

if not success:
    raise Exception('MODFLOW did not terminate normally.')
Example #10
0
                    laycbd=gr.LAYCBD,
                    nper=NPER,
                    perlen=PERLEN,
                    nstp=NSTP,
                    steady=STEADY)
bas = fm.ModflowBas(mf, ibound=IBOUND, strt=STRTHD)
lpf = fm.ModflowLpf(mf,
                    hk=HK,
                    vka=VKA,
                    chani=[1.e-20, 1.e-20],
                    sy=SY,
                    ss=SS,
                    laytyp=LAYTYP,
                    vkcb=VKCB,
                    ipakcb=53)
ghb = fm.ModflowGhb(mf, stress_period_data=GHB, ipakcb=53)
riv = fm.ModflowRiv(mf, stress_period_data=RIV, ipakcb=53)
drn = fm.ModflowDrn(mf, stress_period_data=DRN, ipakcb=53)
wel = fm.ModflowWel(mf, stress_period_data=SEEP, ipakcb=53)
rch = fm.ModflowRch(mf, nrchop=3, rech=RECH, ipakcb=53)
evt = fm.ModflowEvt(mf, nevtop=3, evtr=EVTR, ipakcb=53)
oc = fm.ModflowOc(mf, stress_period_data=OC, compact=True)
#pcg = fm.ModflowPcg(mf, mxiter=200, iter1=200, hclose=0.001, rclose=0.001)
sms = fm.ModflowSms(mf)  #, mxiter=200, iter1=200, hclose=0.001, rclose=0.001)

#%% Write the model input files and run MODFLOW
mf.write_input()
success, mfoutput = mf.run_model(silent=False, pause=False)

print('Running success = {}'.format(success))
if not success: