Ejemplo n.º 1
0
def run():
    # run installed version of flopy or add local path
    try:
        import flopy
    except:
        fpth = os.path.abspath(os.path.join('..', '..'))
        sys.path.append(fpth)
        import flopy

    # Set name of MODFLOW exe
    #  assumes executable is in users path statement
    version = 'mf2005'
    exe_name = 'mf2005'
    exe_mp = 'mp6'
    if platform.system() == 'Windows':
        exe_name += '.exe'
        exe_mp += '.exe'
    mfexe = exe_name

    # Set the paths
    loadpth = os.path.join('..', 'data', 'freyberg')
    modelpth = os.path.join('data')

    # make sure modelpth directory exists
    if not os.path.exists(modelpth):
        os.makedirs(modelpth)

    ml = flopy.modflow.Modflow.load('freyberg.nam', model_ws=loadpth,
                                    exe_name=exe_name, version=version)
    ml.change_model_ws(new_pth=modelpth)
    ml.write_input()
    success, buff = ml.run_model()
    if not success:
        print('Something bad happened.')
    files = ['freyberg.hds', 'freyberg.cbc']
    for f in files:
        if os.path.isfile(os.path.join(modelpth, f)):
            msg = 'Output file located: {}'.format(f)
            print(msg)
        else:
            errmsg = 'Error. Output file cannot be found: {}'.format(f)
            print(errmsg)

    mp = flopy.modpath.Modpath('freybergmp', exe_name=exe_mp, modflowmodel=ml, model_ws=modelpth)
    mpbas = flopy.modpath.ModpathBas(mp, hnoflo=ml.bas6.hnoflo, hdry=ml.lpf.hdry,
                                     ibound=ml.bas6.ibound.array, prsity=0.2, prsityCB=0.2)
    sim = mp.create_mpsim(trackdir='forward', simtype='endpoint', packages='RCH')
    mp.write_input()
    mp.run_model()

    mpp = flopy.modpath.Modpath('freybergmpp', exe_name=exe_mp, modflowmodel=ml, model_ws=modelpth)
    mpbas = flopy.modpath.ModpathBas(mpp, hnoflo=ml.bas6.hnoflo, hdry=ml.lpf.hdry,
                                     ibound=ml.bas6.ibound.array, prsity=0.2, prsityCB=0.2)
    sim = mpp.create_mpsim(trackdir='backward', simtype='pathline', packages='WEL')
    mpp.write_input()
    mpp.run_model()


    ## load and run second example
    # run installed version of flopy or add local path
    try:
        import flopy
    except:
        fpth = os.path.abspath(os.path.join('..', '..'))
        sys.path.append(fpth)
        import flopy

        print(sys.version)
    print('numpy version: {}'.format(np.__version__))
    print('matplotlib version: {}'.format(mpl.__version__))
    print('flopy version: {}'.format(flopy.__version__))

    if not os.path.exists("data"):
        os.mkdir("data")

    from flopy.utils.gridgen import Gridgen
    Lx = 10000.
    Ly = 10500.
    nlay = 3
    nrow = 21
    ncol = 20
    delr = Lx / ncol
    delc = Ly / nrow
    top = 400
    botm = [220, 200, 0]

    ms = flopy.modflow.Modflow()
    dis5 = flopy.modflow.ModflowDis(ms, nlay=nlay, nrow=nrow, ncol=ncol, delr=delr,
                                    delc=delc, top=top, botm=botm)

    model_name = 'mp7p2'
    model_ws = os.path.join('data', 'mp7_ex2', 'mf6')
    gridgen_ws = os.path.join(model_ws, 'gridgen')
    g = Gridgen(dis5, model_ws=gridgen_ws)

    rf0shp = os.path.join(gridgen_ws, 'rf0')
    xmin = 7 * delr
    xmax = 12 * delr
    ymin = 8 * delc
    ymax = 13 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 1, range(nlay))

    rf1shp = os.path.join(gridgen_ws, 'rf1')
    xmin = 8 * delr
    xmax = 11 * delr
    ymin = 9 * delc
    ymax = 12 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 2, range(nlay))

    rf2shp = os.path.join(gridgen_ws, 'rf2')
    xmin = 9 * delr
    xmax = 10 * delr
    ymin = 10 * delc
    ymax = 11 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax), (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 3, range(nlay))

    g.build(verbose=False)

    gridprops = g.get_gridprops_disv()
    ncpl = gridprops['ncpl']
    top = gridprops['top']
    botm = gridprops['botm']
    nvert = gridprops['nvert']
    vertices = gridprops['vertices']
    cell2d = gridprops['cell2d']
    # cellxy = gridprops['cellxy']

    # create simulation
    sim = flopy.mf6.MFSimulation(sim_name=model_name, version='mf6', exe_name='mf6',
                                 sim_ws=model_ws)

    # create tdis package
    tdis_rc = [(1000.0, 1, 1.0)]
    tdis = flopy.mf6.ModflowTdis(sim, pname='tdis', time_units='DAYS',
                                 perioddata=tdis_rc)

    # create gwf model
    gwf = flopy.mf6.ModflowGwf(sim, modelname=model_name,
                               model_nam_file='{}.nam'.format(model_name))
    gwf.name_file.save_flows = True

    # create iterative model solution and register the gwf model with it
    ims = flopy.mf6.ModflowIms(sim, pname='ims', print_option='SUMMARY',
                               complexity='SIMPLE', outer_hclose=1.e-5,
                               outer_maximum=100, under_relaxation='NONE',
                               inner_maximum=100, inner_hclose=1.e-6,
                               rcloserecord=0.1, linear_acceleration='BICGSTAB',
                               scaling_method='NONE', reordering_method='NONE',
                               relaxation_factor=0.99)
    sim.register_ims_package(ims, [gwf.name])

    # disv
    disv = flopy.mf6.ModflowGwfdisv(gwf, nlay=nlay, ncpl=ncpl,
                                    top=top, botm=botm,
                                    nvert=nvert, vertices=vertices,
                                    cell2d=cell2d)

    # initial conditions
    ic = flopy.mf6.ModflowGwfic(gwf, pname='ic', strt=320.)

    # node property flow
    npf = flopy.mf6.ModflowGwfnpf(gwf, xt3doptions=[('xt3d')],
                                  icelltype=[1, 0, 0],
                                  k=[50.0, 0.01, 200.0],
                                  k33=[10., 0.01, 20.])

    # wel
    wellpoints = [(4750., 5250.)]
    welcells = g.intersect(wellpoints, 'point', 0)
    # welspd = flopy.mf6.ModflowGwfwel.stress_period_data.empty(gwf, maxbound=1, aux_vars=['iface'])
    welspd = [[(2, icpl), -150000, 0] for icpl in welcells['nodenumber']]
    wel = flopy.mf6.ModflowGwfwel(gwf, print_input=True,
                                  auxiliary=[('iface',)],
                                  stress_period_data=welspd)

    # rch
    aux = [np.ones(ncpl, dtype=np.int) * 6]
    rch = flopy.mf6.ModflowGwfrcha(gwf, recharge=0.005,
                                   auxiliary=[('iface',)],
                                   aux={0: [6]})
    # riv
    riverline = [[[(Lx - 1., Ly), (Lx - 1., 0.)]]]
    rivcells = g.intersect(riverline, 'line', 0)
    rivspd = [[(0, icpl), 320., 100000., 318] for icpl in rivcells['nodenumber']]
    riv = flopy.mf6.ModflowGwfriv(gwf, stress_period_data=rivspd)

    # output control
    oc = flopy.mf6.ModflowGwfoc(gwf, pname='oc', budget_filerecord='{}.cbb'.format(model_name),
                                head_filerecord='{}.hds'.format(model_name),
                                headprintrecord=[('COLUMNS', 10, 'WIDTH', 15,
                                                  'DIGITS', 6, 'GENERAL')],
                                saverecord=[('HEAD', 'ALL'), ('BUDGET', 'ALL')],
                                printrecord=[('HEAD', 'ALL'), ('BUDGET', 'ALL')])

    sim.write_simulation()
    sim.run_simulation()

    mp_namea = model_name + 'a_mp'
    mp_nameb = model_name + 'b_mp'

    pcoord = np.array([[0.000, 0.125, 0.500],
                       [0.000, 0.375, 0.500],
                       [0.000, 0.625, 0.500],
                       [0.000, 0.875, 0.500],
                       [1.000, 0.125, 0.500],
                       [1.000, 0.375, 0.500],
                       [1.000, 0.625, 0.500],
                       [1.000, 0.875, 0.500],
                       [0.125, 0.000, 0.500],
                       [0.375, 0.000, 0.500],
                       [0.625, 0.000, 0.500],
                       [0.875, 0.000, 0.500],
                       [0.125, 1.000, 0.500],
                       [0.375, 1.000, 0.500],
                       [0.625, 1.000, 0.500],
                       [0.875, 1.000, 0.500]])
    nodew = gwf.disv.ncpl.array * 2 + welcells['nodenumber'][0]
    plocs = [nodew for i in range(pcoord.shape[0])]

    # create particle data
    pa = flopy.modpath.ParticleData(plocs, structured=False,
                                    localx=pcoord[:, 0],
                                    localy=pcoord[:, 1],
                                    localz=pcoord[:, 2],
                                    drape=0)

    # create backward particle group
    fpth = mp_namea + '.sloc'
    pga = flopy.modpath.ParticleGroup(particlegroupname='BACKWARD1', particledata=pa,
                                      filename=fpth)

    facedata = flopy.modpath.FaceDataType(drape=0,
                                          verticaldivisions1=10, horizontaldivisions1=10,
                                          verticaldivisions2=10, horizontaldivisions2=10,
                                          verticaldivisions3=10, horizontaldivisions3=10,
                                          verticaldivisions4=10, horizontaldivisions4=10,
                                          rowdivisions5=0, columndivisions5=0,
                                          rowdivisions6=4, columndivisions6=4)
    pb = flopy.modpath.NodeParticleData(subdivisiondata=facedata, nodes=nodew)
    # create forward particle group
    fpth = mp_nameb + '.sloc'
    pgb = flopy.modpath.ParticleGroupNodeTemplate(particlegroupname='BACKWARD2',
                                                  particledata=pb,
                                                  filename=fpth)

    # create modpath files
    mp = flopy.modpath.Modpath7(modelname=mp_namea, flowmodel=gwf,
                                exe_name='mp7', model_ws=model_ws)
    flopy.modpath.Modpath7Bas(mp, porosity=0.1)
    flopy.modpath.Modpath7Sim(mp, simulationtype='combined',
                              trackingdirection='backward',
                              weaksinkoption='pass_through',
                              weaksourceoption='pass_through',
                              referencetime=0.,
                              stoptimeoption='extend',
                              timepointdata=[500, 1000.],
                              particlegroups=pga)

    # write modpath datasets
    mp.write_input()

    # run modpath
    mp.run_model()

    # create modpath files
    mp = flopy.modpath.Modpath7(modelname=mp_nameb, flowmodel=gwf,
                                exe_name='mp7', model_ws=model_ws)
    flopy.modpath.Modpath7Bas(mp, porosity=0.1)
    flopy.modpath.Modpath7Sim(mp, simulationtype='endpoint',
                              trackingdirection='backward',
                              weaksinkoption='pass_through',
                              weaksourceoption='pass_through',
                              referencetime=0.,
                              stoptimeoption='extend',
                              particlegroups=pgb)

    # write modpath datasets
    mp.write_input()

    # run modpath
    mp.run_model()
    return
Ejemplo n.º 2
0
def test_gridgen():

    # define the base grid and then create a couple levels of nested
    # refinement
    Lx = 10000.
    Ly = 10500.
    nlay = 3
    nrow = 21
    ncol = 20
    delr = Lx / ncol
    delc = Ly / nrow
    top = 400
    botm = [220, 200, np.random.random((nrow, ncol))]

    # create a dummy dis package for gridgen
    ms = flopy.modflow.Modflow()
    dis5 = flopy.modflow.ModflowDis(ms,
                                    nlay=nlay,
                                    nrow=nrow,
                                    ncol=ncol,
                                    delr=delr,
                                    delc=delc,
                                    top=top,
                                    botm=botm)

    sim = flopy.mf6.MFSimulation()
    gwf = gwf = flopy.mf6.ModflowGwf(sim)
    dis6 = flopy.mf6.ModflowGwfdis(gwf,
                                   nlay=nlay,
                                   nrow=nrow,
                                   ncol=ncol,
                                   delr=delr,
                                   delc=delc,
                                   top=top,
                                   botm=botm)

    ms_u = flopy.modflow.Modflow(modelname='mymfusgmodel',
                                 model_ws=cpth,
                                 version='mfusg')
    dis_usg = flopy.modflow.ModflowDis(ms_u,
                                       nlay=nlay,
                                       nrow=nrow,
                                       ncol=ncol,
                                       delr=delr,
                                       delc=delc,
                                       top=top,
                                       botm=botm)

    gridgen_ws = cpth
    g = Gridgen(dis5, model_ws=gridgen_ws, exe_name=exe_name)
    g6 = Gridgen(dis6, model_ws=gridgen_ws, exe_name=exe_name)
    gu = Gridgen(dis_usg,
                 model_ws=gridgen_ws,
                 exe_name=exe_name,
                 vertical_pass_through=True)

    if shapefile is None:
        return  # skip remainder

    rf0shp = os.path.join(gridgen_ws, 'rf0')
    xmin = 7 * delr
    xmax = 12 * delr
    ymin = 8 * delc
    ymax = 13 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax),
                (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 1, range(nlay))
    g6.add_refinement_features(rfpoly, 'polygon', 1, range(nlay))
    gu.add_refinement_features(rfpoly, 'polygon', 1, range(nlay))

    rf1shp = os.path.join(gridgen_ws, 'rf1')
    xmin = 8 * delr
    xmax = 11 * delr
    ymin = 9 * delc
    ymax = 12 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax),
                (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 2, range(nlay))
    g6.add_refinement_features(rfpoly, 'polygon', 2, range(nlay))
    gu.add_refinement_features(rfpoly, 'polygon', 2, range(nlay))

    rf2shp = os.path.join(gridgen_ws, 'rf2')
    xmin = 9 * delr
    xmax = 10 * delr
    ymin = 10 * delc
    ymax = 11 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax),
                (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 3, range(nlay))
    g6.add_refinement_features(rfpoly, 'polygon', 3, range(nlay))
    gu.add_refinement_features(rfpoly, 'polygon', 3, range(nlay))

    # inactivate parts of mfusg layer 2 to test vertical-pass-through option
    xmin = 0 * delr
    xmax = 18 * delr
    ymin = 0 * delc
    ymax = 18 * delc
    adpoly2 = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax),
                 (xmin, ymin)]]]
    gu.add_active_domain(adpoly2, layers=[1])
    adpoly1_3 = [[[(0., 0.), (Lx, 0.), (Lx, Ly), (0., Ly), (0., 0.)]]]
    gu.add_active_domain(adpoly1_3, layers=[0, 2])

    # if gridgen executable is available then do the main part of the test
    if run:

        # Use gridgen to build the grid
        g.build()
        g6.build()

        # test the different gridprops dictionaries, which contain all the
        # information needed to make the different discretization packages
        gridprops = g.get_gridprops_disv()
        gridprops = g.get_gridprops_disu5()
        gridprops = g.get_gridprops_disu6()

        # test the gridgen point intersection
        points = [(4750., 5250.)]
        cells = g.intersect(points, 'point', 0)
        n = cells['nodenumber'][0]
        msg = ('gridgen point intersect did not identify the correct '
               'cell {} <> {}'.format(n, 308))
        assert n == 308, msg

        # test the gridgen line intersection
        line = [[[(Lx, Ly), (Lx, 0.)]]]
        cells = g.intersect(line, 'line', 0)
        nlist = [n for n in cells['nodenumber']]
        nlist2 = [
            19, 650, 39, 630, 59, 610, 79, 590, 99, 570, 119, 550, 139, 530,
            159, 510, 194, 490, 265, 455, 384
        ]
        msg = ('gridgen line intersect did not identify the correct '
               'cells {} <> {}'.format(nlist, nlist2))
        assert nlist == nlist2, msg

        # test getting a modflow-usg disu package
        mu = flopy.modflow.Modflow(version='mfusg', structured=False)
        disu = g.get_disu(mu)

        # test mfusg with vertical pass-through (True above at instantiation)
        gu.build()
        disu_vp = gu.get_disu(ms_u)
        #  -check that node 1 (layer 1) is connected to layer 3 but not layer 2:
        ja0 = disu_vp.ja[:disu_vp.iac[0]]
        msg = ("MFUSG node 1 (layer 1) is not connected to layer 3 but should "
               "be (with vertical pass through activated).")
        assert max(ja0) > sum(disu_vp.nodelay[:2]), msg
        #  -check that node 1 (layer 1) is not connected to any layer 2 nodes
        msg = ("MFUSG node 1 (layer 1) is connected to layer 2 but should not "
               "be (with vertical pass through activated).")
        assert len(ja0[(ja0 > disu_vp.nodelay[0]) & \
                       (ja0 <= sum(disu_vp.nodelay[:2]))]
                   ) == 0, msg
        #ms_u.disu.write_file()

        # test mfusg without vertical pass-through
        gu.vertical_pass_through = False
        gu.build()
        disu_vp = gu.get_disu(ms_u)
        #  -check that node 1 (layer 1) is connected to layer 1 only:
        ja0 = disu_vp.ja[:disu_vp.iac[0]]
        msg = ("MFUSG node 1 (layer 1) is connected to layer 2 or 3 but "
               "should not be (without vertical pass through activated).")
        assert max(ja0) <= disu_vp.nodelay[0], msg

    return
Ejemplo n.º 3
0
def test_mf6disv():

    if gridgen_exe is None:
        print(
            "Unable to run test_mf6disv(). Gridgen executable not available.")
        return

    if Polygon is None:
        print("Unable to run test_mf6disv(). shapely is not available.")
        return

    name = "dummy"
    nlay = 3
    nrow = 10
    ncol = 10
    delr = delc = 1.0
    top = 1
    bot = 0
    dz = (top - bot) / nlay
    botm = [top - k * dz for k in range(1, nlay + 1)]

    # Create a dummy model and regular grid to use as the base grid for gridgen
    sim = flopy.mf6.MFSimulation(sim_name=name,
                                 sim_ws=gridgen_ws,
                                 exe_name="mf6")
    gwf = flopy.mf6.ModflowGwf(sim, modelname=name)

    dis = flopy.mf6.ModflowGwfdis(
        gwf,
        nlay=nlay,
        nrow=nrow,
        ncol=ncol,
        delr=delr,
        delc=delc,
        top=top,
        botm=botm,
    )

    # Create and build the gridgen model with a refined area in the middle
    g = Gridgen(dis, model_ws=gridgen_ws)
    polys = [Polygon([(4, 4), (6, 4), (6, 6), (4, 6)])]
    g.add_refinement_features(polys, "polygon", 3, range(nlay))
    g.build()
    disv_gridprops = g.get_gridprops_disv()

    # find the cell numbers for constant heads
    chdspd = []
    ilay = 0
    for x, y, head in [(0, 10, 1.0), (10, 0, 0.0)]:
        ra = g.intersect([(x, y)], "point", ilay)
        ic = ra["nodenumber"][0]
        chdspd.append([(ilay, ic), head])

    # build run and post-process the MODFLOW 6 model
    ws = os.path.join(tpth, "gridgen_disv")
    name = "mymodel"
    sim = flopy.mf6.MFSimulation(
        sim_name=name,
        sim_ws=ws,
        exe_name="mf6",
        verbosity_level=VERBOSITY_LEVEL,
    )
    tdis = flopy.mf6.ModflowTdis(sim)
    ims = flopy.mf6.ModflowIms(sim, linear_acceleration="bicgstab")
    gwf = flopy.mf6.ModflowGwf(sim, modelname=name, save_flows=True)
    disv = flopy.mf6.ModflowGwfdisv(gwf, **disv_gridprops)
    ic = flopy.mf6.ModflowGwfic(gwf)
    npf = flopy.mf6.ModflowGwfnpf(gwf,
                                  xt3doptions=True,
                                  save_specific_discharge=True)
    chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data=chdspd)
    budget_file = name + ".bud"
    head_file = name + ".hds"
    oc = flopy.mf6.ModflowGwfoc(
        gwf,
        budget_filerecord=budget_file,
        head_filerecord=head_file,
        saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")],
    )
    sim.write_simulation()

    gwf.modelgrid.set_coord_info(angrot=15)

    # write grid and model shapefiles
    fname = os.path.join(ws, "grid.shp")
    gwf.modelgrid.write_shapefile(fname)
    fname = os.path.join(ws, "model.shp")
    gwf.export(fname)

    if mf6_exe is not None:
        sim.run_simulation(silent=True)
        head = flopy.utils.HeadFile(os.path.join(ws, head_file)).get_data()
        bud = flopy.utils.CellBudgetFile(os.path.join(ws, budget_file),
                                         precision="double")
        spdis = bud.get_data(text="DATA-SPDIS")[0]

        if matplotlib is not None:
            f = plt.figure(figsize=(10, 10))
            vmin = head.min()
            vmax = head.max()
            for ilay in range(gwf.modelgrid.nlay):
                ax = plt.subplot(1, gwf.modelgrid.nlay, ilay + 1)
                pmv = flopy.plot.PlotMapView(gwf, layer=ilay, ax=ax)
                ax.set_aspect("equal")
                pmv.plot_array(head.flatten(),
                               cmap="jet",
                               vmin=vmin,
                               vmax=vmax)
                pmv.plot_grid(colors="k", alpha=0.1)
                pmv.contour_array(
                    head,
                    levels=[0.2, 0.4, 0.6, 0.8],
                    linewidths=3.0,
                    vmin=vmin,
                    vmax=vmax,
                )
                ax.set_title("Layer {}".format(ilay + 1))
                pmv.plot_specific_discharge(spdis, color="white")
            fname = "results.png"
            fname = os.path.join(ws, fname)
            plt.savefig(fname)
            plt.close("all")

    return
Ejemplo n.º 4
0
def run():
    # run installed version of flopy or add local path
    try:
        import flopy
    except:
        fpth = os.path.abspath(os.path.join('..', '..'))
        sys.path.append(fpth)
        import flopy

    # Set name of MODFLOW exe
    #  assumes executable is in users path statement
    version = 'mf2005'
    exe_name = 'mf2005'
    exe_mp = 'mp6'
    if platform.system() == 'Windows':
        exe_name += '.exe'
        exe_mp += '.exe'
    mfexe = exe_name

    # Set the paths
    loadpth = os.path.join('..', 'data', 'freyberg')
    modelpth = os.path.join('data')

    # make sure modelpth directory exists
    if not os.path.exists(modelpth):
        os.makedirs(modelpth)

    ml = flopy.modflow.Modflow.load('freyberg.nam',
                                    model_ws=loadpth,
                                    exe_name=exe_name,
                                    version=version)
    ml.change_model_ws(new_pth=modelpth)
    ml.write_input()
    success, buff = ml.run_model()
    if not success:
        print('Something bad happened.')
    files = ['freyberg.hds', 'freyberg.cbc']
    for f in files:
        if os.path.isfile(os.path.join(modelpth, f)):
            msg = 'Output file located: {}'.format(f)
            print(msg)
        else:
            errmsg = 'Error. Output file cannot be found: {}'.format(f)
            print(errmsg)

    mp = flopy.modpath.Modpath('freybergmp',
                               exe_name=exe_mp,
                               modflowmodel=ml,
                               model_ws=modelpth)
    mpbas = flopy.modpath.ModpathBas(mp,
                                     hnoflo=ml.bas6.hnoflo,
                                     hdry=ml.lpf.hdry,
                                     ibound=ml.bas6.ibound.array,
                                     prsity=0.2,
                                     prsityCB=0.2)
    sim = mp.create_mpsim(trackdir='forward',
                          simtype='endpoint',
                          packages='RCH')
    mp.write_input()
    mp.run_model()

    mpp = flopy.modpath.Modpath('freybergmpp',
                                exe_name=exe_mp,
                                modflowmodel=ml,
                                model_ws=modelpth)
    mpbas = flopy.modpath.ModpathBas(mpp,
                                     hnoflo=ml.bas6.hnoflo,
                                     hdry=ml.lpf.hdry,
                                     ibound=ml.bas6.ibound.array,
                                     prsity=0.2,
                                     prsityCB=0.2)
    sim = mpp.create_mpsim(trackdir='backward',
                           simtype='pathline',
                           packages='WEL')
    mpp.write_input()
    mpp.run_model()

    ## load and run second example
    # run installed version of flopy or add local path
    try:
        import flopy
    except:
        fpth = os.path.abspath(os.path.join('..', '..'))
        sys.path.append(fpth)
        import flopy

        print(sys.version)
    print('numpy version: {}'.format(np.__version__))
    print('matplotlib version: {}'.format(mpl.__version__))
    print('flopy version: {}'.format(flopy.__version__))

    if not os.path.exists("data"):
        os.mkdir("data")

    from flopy.utils.gridgen import Gridgen
    Lx = 10000.
    Ly = 10500.
    nlay = 3
    nrow = 21
    ncol = 20
    delr = Lx / ncol
    delc = Ly / nrow
    top = 400
    botm = [220, 200, 0]

    ms = flopy.modflow.Modflow()
    dis5 = flopy.modflow.ModflowDis(ms,
                                    nlay=nlay,
                                    nrow=nrow,
                                    ncol=ncol,
                                    delr=delr,
                                    delc=delc,
                                    top=top,
                                    botm=botm)

    model_name = 'mp7p2'
    model_ws = os.path.join('data', 'mp7_ex2', 'mf6')
    gridgen_ws = os.path.join(model_ws, 'gridgen')
    g = Gridgen(dis5, model_ws=gridgen_ws)

    rf0shp = os.path.join(gridgen_ws, 'rf0')
    xmin = 7 * delr
    xmax = 12 * delr
    ymin = 8 * delc
    ymax = 13 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax),
                (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 1, range(nlay))

    rf1shp = os.path.join(gridgen_ws, 'rf1')
    xmin = 8 * delr
    xmax = 11 * delr
    ymin = 9 * delc
    ymax = 12 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax),
                (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 2, range(nlay))

    rf2shp = os.path.join(gridgen_ws, 'rf2')
    xmin = 9 * delr
    xmax = 10 * delr
    ymin = 10 * delc
    ymax = 11 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax),
                (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 3, range(nlay))

    g.build(verbose=False)

    gridprops = g.get_gridprops_disv()
    ncpl = gridprops['ncpl']
    top = gridprops['top']
    botm = gridprops['botm']
    nvert = gridprops['nvert']
    vertices = gridprops['vertices']
    cell2d = gridprops['cell2d']
    # cellxy = gridprops['cellxy']

    # create simulation
    sim = flopy.mf6.MFSimulation(sim_name=model_name,
                                 version='mf6',
                                 exe_name='mf6',
                                 sim_ws=model_ws)

    # create tdis package
    tdis_rc = [(1000.0, 1, 1.0)]
    tdis = flopy.mf6.ModflowTdis(sim,
                                 pname='tdis',
                                 time_units='DAYS',
                                 perioddata=tdis_rc)

    # create gwf model
    gwf = flopy.mf6.ModflowGwf(sim,
                               modelname=model_name,
                               model_nam_file='{}.nam'.format(model_name))
    gwf.name_file.save_flows = True

    # create iterative model solution and register the gwf model with it
    ims = flopy.mf6.ModflowIms(sim,
                               pname='ims',
                               print_option='SUMMARY',
                               complexity='SIMPLE',
                               outer_hclose=1.e-5,
                               outer_maximum=100,
                               under_relaxation='NONE',
                               inner_maximum=100,
                               inner_hclose=1.e-6,
                               rcloserecord=0.1,
                               linear_acceleration='BICGSTAB',
                               scaling_method='NONE',
                               reordering_method='NONE',
                               relaxation_factor=0.99)
    sim.register_ims_package(ims, [gwf.name])

    # disv
    disv = flopy.mf6.ModflowGwfdisv(gwf,
                                    nlay=nlay,
                                    ncpl=ncpl,
                                    top=top,
                                    botm=botm,
                                    nvert=nvert,
                                    vertices=vertices,
                                    cell2d=cell2d)

    # initial conditions
    ic = flopy.mf6.ModflowGwfic(gwf, pname='ic', strt=320.)

    # node property flow
    npf = flopy.mf6.ModflowGwfnpf(gwf,
                                  xt3doptions=[('xt3d')],
                                  icelltype=[1, 0, 0],
                                  k=[50.0, 0.01, 200.0],
                                  k33=[10., 0.01, 20.])

    # wel
    wellpoints = [(4750., 5250.)]
    welcells = g.intersect(wellpoints, 'point', 0)
    # welspd = flopy.mf6.ModflowGwfwel.stress_period_data.empty(gwf, maxbound=1, aux_vars=['iface'])
    welspd = [[(2, icpl), -150000, 0] for icpl in welcells['nodenumber']]
    wel = flopy.mf6.ModflowGwfwel(gwf,
                                  print_input=True,
                                  auxiliary=[('iface', )],
                                  stress_period_data=welspd)

    # rch
    aux = [np.ones(ncpl, dtype=np.int) * 6]
    rch = flopy.mf6.ModflowGwfrcha(gwf,
                                   recharge=0.005,
                                   auxiliary=[('iface', )],
                                   aux={0: [6]})
    # riv
    riverline = [[[(Lx - 1., Ly), (Lx - 1., 0.)]]]
    rivcells = g.intersect(riverline, 'line', 0)
    rivspd = [[(0, icpl), 320., 100000., 318]
              for icpl in rivcells['nodenumber']]
    riv = flopy.mf6.ModflowGwfriv(gwf, stress_period_data=rivspd)

    # output control
    oc = flopy.mf6.ModflowGwfoc(gwf,
                                pname='oc',
                                budget_filerecord='{}.cbb'.format(model_name),
                                head_filerecord='{}.hds'.format(model_name),
                                headprintrecord=[('COLUMNS', 10, 'WIDTH', 15,
                                                  'DIGITS', 6, 'GENERAL')],
                                saverecord=[('HEAD', 'ALL'),
                                            ('BUDGET', 'ALL')],
                                printrecord=[('HEAD', 'ALL'),
                                             ('BUDGET', 'ALL')])

    sim.write_simulation()
    sim.run_simulation()

    mp_namea = model_name + 'a_mp'
    mp_nameb = model_name + 'b_mp'

    pcoord = np.array([[0.000, 0.125, 0.500], [0.000, 0.375, 0.500],
                       [0.000, 0.625, 0.500], [0.000, 0.875, 0.500],
                       [1.000, 0.125, 0.500], [1.000, 0.375, 0.500],
                       [1.000, 0.625, 0.500], [1.000, 0.875, 0.500],
                       [0.125, 0.000, 0.500], [0.375, 0.000, 0.500],
                       [0.625, 0.000, 0.500], [0.875, 0.000, 0.500],
                       [0.125, 1.000, 0.500], [0.375, 1.000, 0.500],
                       [0.625, 1.000, 0.500], [0.875, 1.000, 0.500]])
    nodew = gwf.disv.ncpl.array * 2 + welcells['nodenumber'][0]
    plocs = [nodew for i in range(pcoord.shape[0])]

    # create particle data
    pa = flopy.modpath.ParticleData(plocs,
                                    structured=False,
                                    localx=pcoord[:, 0],
                                    localy=pcoord[:, 1],
                                    localz=pcoord[:, 2],
                                    drape=0)

    # create backward particle group
    fpth = mp_namea + '.sloc'
    pga = flopy.modpath.ParticleGroup(particlegroupname='BACKWARD1',
                                      particledata=pa,
                                      filename=fpth)

    facedata = flopy.modpath.FaceDataType(drape=0,
                                          verticaldivisions1=10,
                                          horizontaldivisions1=10,
                                          verticaldivisions2=10,
                                          horizontaldivisions2=10,
                                          verticaldivisions3=10,
                                          horizontaldivisions3=10,
                                          verticaldivisions4=10,
                                          horizontaldivisions4=10,
                                          rowdivisions5=0,
                                          columndivisions5=0,
                                          rowdivisions6=4,
                                          columndivisions6=4)
    pb = flopy.modpath.NodeParticleData(subdivisiondata=facedata, nodes=nodew)
    # create forward particle group
    fpth = mp_nameb + '.sloc'
    pgb = flopy.modpath.ParticleGroupNodeTemplate(
        particlegroupname='BACKWARD2', particledata=pb, filename=fpth)

    # create modpath files
    mp = flopy.modpath.Modpath7(modelname=mp_namea,
                                flowmodel=gwf,
                                exe_name='mp7',
                                model_ws=model_ws)
    flopy.modpath.Modpath7Bas(mp, porosity=0.1)
    flopy.modpath.Modpath7Sim(mp,
                              simulationtype='combined',
                              trackingdirection='backward',
                              weaksinkoption='pass_through',
                              weaksourceoption='pass_through',
                              referencetime=0.,
                              stoptimeoption='extend',
                              timepointdata=[500, 1000.],
                              particlegroups=pga)

    # write modpath datasets
    mp.write_input()

    # run modpath
    mp.run_model()

    # create modpath files
    mp = flopy.modpath.Modpath7(modelname=mp_nameb,
                                flowmodel=gwf,
                                exe_name='mp7',
                                model_ws=model_ws)
    flopy.modpath.Modpath7Bas(mp, porosity=0.1)
    flopy.modpath.Modpath7Sim(mp,
                              simulationtype='endpoint',
                              trackingdirection='backward',
                              weaksinkoption='pass_through',
                              weaksourceoption='pass_through',
                              referencetime=0.,
                              stoptimeoption='extend',
                              particlegroups=pgb)

    # write modpath datasets
    mp.write_input()

    # run modpath
    mp.run_model()
    return
Ejemplo n.º 5
0
def test_mf6disu():

    name = 'dummy'
    nlay = 3
    nrow = 10
    ncol = 10
    delr = delc = 1.
    top = 1
    bot = 0
    dz = (top - bot) / nlay
    botm = [top - k * dz for k in range(1, nlay + 1)]

    # Create a dummy model and regular grid to use as the base grid for gridgen
    sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=gridgen_ws,
                                 exe_name='mf6')
    gwf = flopy.mf6.ModflowGwf(sim, modelname=name)

    dis = flopy.mf6.ModflowGwfdis(gwf, nlay=nlay, nrow=nrow, ncol=ncol,
                                  delr=delr, delc=delc,
                                  top=top, botm=botm)

    # Create and build the gridgen model with a refined area in the middle
    g = Gridgen(dis, model_ws=gridgen_ws)
    polys = [Polygon([(4, 4), (6, 4), (6, 6), (4, 6)])]
    g.add_refinement_features(polys, 'polygon', 3, layers=[0])
    g.build()
    disu_gridprops = g.get_gridprops_disu6()

    chdspd = []
    for x, y, head in [(0, 10, 1.), (10, 0, 0.)]:
        ra = g.intersect([(x, y)], 'point', 0)
        ic = ra['nodenumber'][0]
        chdspd.append([(ic,), head])

    # build run and post-process the MODFLOW 6 model
    ws = os.path.join(tpth, 'gridgen_disu')
    name = 'mymodel'
    sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=ws, exe_name='mf6',
                                 verbosity_level=VERBOSITY_LEVEL)
    tdis = flopy.mf6.ModflowTdis(sim)
    ims = flopy.mf6.ModflowIms(sim, linear_acceleration='bicgstab')
    gwf = flopy.mf6.ModflowGwf(sim, modelname=name, save_flows=True)
    disu = flopy.mf6.ModflowGwfdisu(gwf, **disu_gridprops)
    ic = flopy.mf6.ModflowGwfic(gwf)
    npf = flopy.mf6.ModflowGwfnpf(gwf, xt3doptions=True,
                                  save_specific_discharge=True)
    chd = flopy.mf6.ModflowGwfchd(gwf, stress_period_data=chdspd)
    budget_file = name + '.bud'
    head_file = name + '.hds'
    oc = flopy.mf6.ModflowGwfoc(gwf,
                                budget_filerecord=budget_file,
                                head_filerecord=head_file,
                                saverecord=[('HEAD', 'ALL'), ('BUDGET', 'ALL')])
    sim.write_simulation()

    gwf.modelgrid.set_coord_info(angrot=15)

    # The flopy Gridgen object includes the plottable layer number to the
    # diagonal position in the ihc array.  This is why and how modelgrid.nlay
    # is set to 3 and ncpl has a different number of cells per layer.
    assert gwf.modelgrid.nlay == 3
    assert np.allclose(gwf.modelgrid.ncpl, np.array([436, 184, 112]))

    # write grid and model shapefiles
    fname = os.path.join(ws, 'grid.shp')
    gwf.modelgrid.write_shapefile(fname)
    fname = os.path.join(ws, 'model.shp')
    gwf.export(fname)

    if mf6_exe is not None:
        sim.run_simulation(silent=True)
        head = flopy.utils.HeadFile(os.path.join(ws, head_file)).get_data()
        bud = flopy.utils.CellBudgetFile(os.path.join(ws, budget_file),
                                         precision='double')
        spdis = bud.get_data(text='DATA-SPDIS')[0]

        if matplotlib is not None:
            f = plt.figure(figsize=(10, 10))
            vmin = head.min()
            vmax = head.max()
            for ilay in range(gwf.modelgrid.nlay):
                ax = plt.subplot(1, gwf.modelgrid.nlay, ilay + 1)
                pmv = flopy.plot.PlotMapView(gwf, layer=ilay, ax=ax)
                ax.set_aspect('equal')
                pmv.plot_array(head.flatten(), cmap='jet', vmin=vmin,
                               vmax=vmax)
                pmv.plot_grid(colors='k', alpha=0.1)
                pmv.contour_array(head, levels=[.2, .4, .6, .8], linewidths=3.,
                                  vmin=vmin, vmax=vmax)
                ax.set_title("Layer {}".format(ilay + 1))
                pmv.plot_specific_discharge(spdis, color='white')
            fname = 'results.png'
            fname = os.path.join(ws, fname)
            plt.savefig(fname)
            plt.close('all')

    return
Ejemplo n.º 6
0
def test_mfusg():

    name = "dummy"
    nlay = 3
    nrow = 10
    ncol = 10
    delr = delc = 1.0
    top = 1
    bot = 0
    dz = (top - bot) / nlay
    botm = [top - k * dz for k in range(1, nlay + 1)]

    # create dummy model and dis package for gridgen
    m = flopy.modflow.Modflow(modelname=name, model_ws=gridgen_ws)
    dis = flopy.modflow.ModflowDis(
        m,
        nlay=nlay,
        nrow=nrow,
        ncol=ncol,
        delr=delr,
        delc=delc,
        top=top,
        botm=botm,
    )

    # Create and build the gridgen model with a refined area in the middle
    g = Gridgen(dis, model_ws=gridgen_ws)
    polys = [Polygon([(4, 4), (6, 4), (6, 6), (4, 6)])]
    g.add_refinement_features(polys, "polygon", 3, layers=[0])
    g.build()

    chdspd = []
    for x, y, head in [(0, 10, 1.0), (10, 0, 0.0)]:
        ra = g.intersect([(x, y)], "point", 0)
        ic = ra["nodenumber"][0]
        chdspd.append([ic, head, head])

    # gridprops = g.get_gridprops()
    gridprops = g.get_gridprops_disu5()

    # create the mfusg modoel
    ws = os.path.join(tpth, "gridgen_mfusg")
    name = "mymodel"
    m = flopy.modflow.Modflow(
        modelname=name,
        model_ws=ws,
        version="mfusg",
        exe_name=mfusg_exe,
        structured=False,
    )
    disu = flopy.modflow.ModflowDisU(m, **gridprops)
    bas = flopy.modflow.ModflowBas(m)
    lpf = flopy.modflow.ModflowLpf(m)
    chd = flopy.modflow.ModflowChd(m, stress_period_data=chdspd)
    sms = flopy.modflow.ModflowSms(m)
    oc = flopy.modflow.ModflowOc(m, stress_period_data={(0, 0): ["save head"]})
    m.write_input()

    # MODFLOW-USG does not have vertices, so we need to create
    # and unstructured grid and then assign it to the model. This
    # will allow plotting and other features to work properly.
    gridprops_ug = g.get_gridprops_unstructuredgrid()
    ugrid = flopy.discretization.UnstructuredGrid(**gridprops_ug, angrot=-15)
    m.modelgrid = ugrid

    if mfusg_exe is not None:
        m.run_model()

        # head is returned as a list of head arrays for each layer
        head_file = os.path.join(ws, name + ".hds")
        head = flopy.utils.HeadUFile(head_file).get_data()

        if matplotlib is not None:
            f = plt.figure(figsize=(10, 10))
            vmin = 0.0
            vmax = 1.0
            for ilay in range(disu.nlay):
                ax = plt.subplot(1, g.nlay, ilay + 1)
                pmv = flopy.plot.PlotMapView(m, layer=ilay, ax=ax)
                ax.set_aspect("equal")
                pmv.plot_array(head[ilay], cmap="jet", vmin=vmin, vmax=vmax)
                pmv.plot_grid(colors="k", alpha=0.1)
                pmv.contour_array(head[ilay],
                                  levels=[0.2, 0.4, 0.6, 0.8],
                                  linewidths=3.0)
                ax.set_title("Layer {}".format(ilay + 1))
                # pmv.plot_specific_discharge(spdis, color='white')
            fname = "results.png"
            fname = os.path.join(ws, fname)
            plt.savefig(fname)
            plt.close("all")

        # re-run with an LPF keyword specified. This would have thrown an error
        # before the addition of ikcflag to mflpf.py (flopy 3.3.3 and earlier).
        lpf = flopy.modflow.ModflowLpf(m, novfc=True, nocvcorrection=True)
        m.write_input()
        m.run_model()

        # also test load of unstructured LPF with keywords
        lpf2 = flopy.modflow.ModflowLpf.load(os.path.join(ws, name + ".lpf"),
                                             m,
                                             check=False)
        msg = "NOCVCORRECTION and NOVFC should be in lpf options but at least one is not."
        assert ("NOVFC" in lpf2.options.upper()
                and "NOCVCORRECTION" in lpf2.options.upper()), msg

    return
Ejemplo n.º 7
0
def run():
    ## load and run vertex grid example
    # run installed version of flopy or add local path
    try:
        import flopy
    except:
        fpth = os.path.abspath(os.path.join("../..", ".."))
        sys.path.append(fpth)
        import flopy

        print(sys.version)
    print("numpy version: {}".format(np.__version__))
    print("matplotlib version: {}".format(mpl.__version__))
    print("flopy version: {}".format(flopy.__version__))

    if not os.path.exists("data"):
        os.mkdir("data")

    from flopy.utils.gridgen import Gridgen

    Lx = 10000.0
    Ly = 10500.0
    nlay = 3
    nrow = 21
    ncol = 20
    delr = Lx / ncol
    delc = Ly / nrow
    top = 400
    botm = [220, 200, 0]

    ms = flopy.modflow.Modflow()
    dis5 = flopy.modflow.ModflowDis(
        ms,
        nlay=nlay,
        nrow=nrow,
        ncol=ncol,
        delr=delr,
        delc=delc,
        top=top,
        botm=botm,
    )

    model_name = "mp7p2"
    model_ws = os.path.join("data", "mp7_ex2", "mf6")
    gridgen_ws = os.path.join(model_ws, "gridgen")
    g = Gridgen(dis5, model_ws=gridgen_ws)

    rf0shp = os.path.join(gridgen_ws, "rf0")
    xmin = 7 * delr
    xmax = 12 * delr
    ymin = 8 * delc
    ymax = 13 * delc
    rfpoly = [[[
        (xmin, ymin),
        (xmax, ymin),
        (xmax, ymax),
        (xmin, ymax),
        (xmin, ymin),
    ]]]
    g.add_refinement_features(rfpoly, "polygon", 1, range(nlay))

    rf1shp = os.path.join(gridgen_ws, "rf1")
    xmin = 8 * delr
    xmax = 11 * delr
    ymin = 9 * delc
    ymax = 12 * delc
    rfpoly = [[[
        (xmin, ymin),
        (xmax, ymin),
        (xmax, ymax),
        (xmin, ymax),
        (xmin, ymin),
    ]]]
    g.add_refinement_features(rfpoly, "polygon", 2, range(nlay))

    rf2shp = os.path.join(gridgen_ws, "rf2")
    xmin = 9 * delr
    xmax = 10 * delr
    ymin = 10 * delc
    ymax = 11 * delc
    rfpoly = [[[
        (xmin, ymin),
        (xmax, ymin),
        (xmax, ymax),
        (xmin, ymax),
        (xmin, ymin),
    ]]]
    g.add_refinement_features(rfpoly, "polygon", 3, range(nlay))

    g.build(verbose=False)

    gridprops = g.get_gridprops_disv()
    ncpl = gridprops["ncpl"]
    top = gridprops["top"]
    botm = gridprops["botm"]
    nvert = gridprops["nvert"]
    vertices = gridprops["vertices"]
    cell2d = gridprops["cell2d"]
    # cellxy = gridprops['cellxy']

    # create simulation
    sim = flopy.mf6.MFSimulation(sim_name=model_name,
                                 version="mf6",
                                 exe_name="mf6",
                                 sim_ws=model_ws)

    # create tdis package
    tdis_rc = [(1000.0, 1, 1.0)]
    tdis = flopy.mf6.ModflowTdis(sim,
                                 pname="tdis",
                                 time_units="DAYS",
                                 perioddata=tdis_rc)

    # create gwf model
    gwf = flopy.mf6.ModflowGwf(sim,
                               modelname=model_name,
                               model_nam_file="{}.nam".format(model_name))
    gwf.name_file.save_flows = True

    # create iterative model solution and register the gwf model with it
    ims = flopy.mf6.ModflowIms(
        sim,
        pname="ims",
        print_option="SUMMARY",
        complexity="SIMPLE",
        outer_hclose=1.0e-5,
        outer_maximum=100,
        under_relaxation="NONE",
        inner_maximum=100,
        inner_hclose=1.0e-6,
        rcloserecord=0.1,
        linear_acceleration="BICGSTAB",
        scaling_method="NONE",
        reordering_method="NONE",
        relaxation_factor=0.99,
    )
    sim.register_ims_package(ims, [gwf.name])

    # disv
    disv = flopy.mf6.ModflowGwfdisv(
        gwf,
        nlay=nlay,
        ncpl=ncpl,
        top=top,
        botm=botm,
        nvert=nvert,
        vertices=vertices,
        cell2d=cell2d,
    )

    # initial conditions
    ic = flopy.mf6.ModflowGwfic(gwf, pname="ic", strt=320.0)

    # node property flow
    npf = flopy.mf6.ModflowGwfnpf(
        gwf,
        xt3doptions=[("xt3d")],
        save_specific_discharge=True,
        icelltype=[1, 0, 0],
        k=[50.0, 0.01, 200.0],
        k33=[10.0, 0.01, 20.0],
    )

    # wel
    wellpoints = [(4750.0, 5250.0)]
    welcells = g.intersect(wellpoints, "point", 0)
    # welspd = flopy.mf6.ModflowGwfwel.stress_period_data.empty(gwf, maxbound=1, aux_vars=['iface'])
    welspd = [[(2, icpl), -150000, 0] for icpl in welcells["nodenumber"]]
    wel = flopy.mf6.ModflowGwfwel(
        gwf,
        print_input=True,
        auxiliary=[("iface", )],
        stress_period_data=welspd,
    )

    # rch
    aux = [np.ones(ncpl, dtype=int) * 6]
    rch = flopy.mf6.ModflowGwfrcha(gwf,
                                   recharge=0.005,
                                   auxiliary=[("iface", )],
                                   aux={0: [6]})
    # riv
    riverline = [[[(Lx - 1.0, Ly), (Lx - 1.0, 0.0)]]]
    rivcells = g.intersect(riverline, "line", 0)
    rivspd = [[(0, icpl), 320.0, 100000.0, 318]
              for icpl in rivcells["nodenumber"]]
    riv = flopy.mf6.ModflowGwfriv(gwf, stress_period_data=rivspd)

    # output control
    oc = flopy.mf6.ModflowGwfoc(
        gwf,
        pname="oc",
        budget_filerecord="{}.cbb".format(model_name),
        head_filerecord="{}.hds".format(model_name),
        headprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")],
        saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")],
        printrecord=[("HEAD", "ALL"), ("BUDGET", "ALL")],
    )

    sim.write_simulation()
    sim.run_simulation()

    mp_namea = model_name + "a_mp"
    mp_nameb = model_name + "b_mp"

    pcoord = np.array([
        [0.000, 0.125, 0.500],
        [0.000, 0.375, 0.500],
        [0.000, 0.625, 0.500],
        [0.000, 0.875, 0.500],
        [1.000, 0.125, 0.500],
        [1.000, 0.375, 0.500],
        [1.000, 0.625, 0.500],
        [1.000, 0.875, 0.500],
        [0.125, 0.000, 0.500],
        [0.375, 0.000, 0.500],
        [0.625, 0.000, 0.500],
        [0.875, 0.000, 0.500],
        [0.125, 1.000, 0.500],
        [0.375, 1.000, 0.500],
        [0.625, 1.000, 0.500],
        [0.875, 1.000, 0.500],
    ])
    nodew = gwf.disv.ncpl.array * 2 + welcells["nodenumber"][0]
    plocs = [nodew for i in range(pcoord.shape[0])]

    # create particle data
    pa = flopy.modpath.ParticleData(
        plocs,
        structured=False,
        localx=pcoord[:, 0],
        localy=pcoord[:, 1],
        localz=pcoord[:, 2],
        drape=0,
    )

    # create backward particle group
    fpth = mp_namea + ".sloc"
    pga = flopy.modpath.ParticleGroup(particlegroupname="BACKWARD1",
                                      particledata=pa,
                                      filename=fpth)

    facedata = flopy.modpath.FaceDataType(
        drape=0,
        verticaldivisions1=10,
        horizontaldivisions1=10,
        verticaldivisions2=10,
        horizontaldivisions2=10,
        verticaldivisions3=10,
        horizontaldivisions3=10,
        verticaldivisions4=10,
        horizontaldivisions4=10,
        rowdivisions5=0,
        columndivisions5=0,
        rowdivisions6=4,
        columndivisions6=4,
    )
    pb = flopy.modpath.NodeParticleData(subdivisiondata=facedata, nodes=nodew)
    # create forward particle group
    fpth = mp_nameb + ".sloc"
    pgb = flopy.modpath.ParticleGroupNodeTemplate(
        particlegroupname="BACKWARD2", particledata=pb, filename=fpth)

    # create modpath files
    mp = flopy.modpath.Modpath7(modelname=mp_namea,
                                flowmodel=gwf,
                                exe_name="mp7",
                                model_ws=model_ws)
    flopy.modpath.Modpath7Bas(mp, porosity=0.1)
    flopy.modpath.Modpath7Sim(
        mp,
        simulationtype="combined",
        trackingdirection="backward",
        weaksinkoption="pass_through",
        weaksourceoption="pass_through",
        referencetime=0.0,
        stoptimeoption="extend",
        timepointdata=[500, 1000.0],
        particlegroups=pga,
    )

    # write modpath datasets
    mp.write_input()

    # run modpath
    mp.run_model()

    # create modpath files
    mp = flopy.modpath.Modpath7(modelname=mp_nameb,
                                flowmodel=gwf,
                                exe_name="mp7",
                                model_ws=model_ws)
    flopy.modpath.Modpath7Bas(mp, porosity=0.1)
    flopy.modpath.Modpath7Sim(
        mp,
        simulationtype="endpoint",
        trackingdirection="backward",
        weaksinkoption="pass_through",
        weaksourceoption="pass_through",
        referencetime=0.0,
        stoptimeoption="extend",
        particlegroups=pgb,
    )

    # write modpath datasets
    mp.write_input()

    # run modpath
    mp.run_model()
    return
Ejemplo n.º 8
0
                          edgecolor='none',
                          alpha=0.2)
flopy.plot.plot_shapefile(rf1shp,
                          ax=ax,
                          linewidth=10,
                          alpha=0.2,
                          color='darkblue')
flopy.plot.plot_shapefile(rf0shp, ax=ax, facecolor='red', radius=1, alpha=0.2)
mpl.pyplot.savefig(os.path.join(model_ws, 'fig2.png'))

mu = flopy.modflow.Modflow(model_ws=model_ws, modelname='mfusg')
disu = g.get_disu(mu)
disu.write_file()
# print(disu)

adpoly_intersect = g.intersect(adpoly, 'polygon', 0)
print(adpoly_intersect.dtype.names)
print(adpoly_intersect)
print(adpoly_intersect.nodenumber)

well_intersect = g.intersect(wells, 'point', 0)
print(well_intersect.dtype.names)
print(well_intersect)
print(well_intersect.nodenumber)

river_intersect = g.intersect(river, 'line', 0)
print(river_intersect.dtype.names)
# print(river_intersect)
# print(river_intersect.nodenumber)

# Plot Intersected Features
Ejemplo n.º 9
0
def test_gridgen():

    # define the base grid and then create a couple levels of nested
    # refinement
    Lx = 10000.
    Ly = 10500.
    nlay = 3
    nrow = 21
    ncol = 20
    delr = Lx / ncol
    delc = Ly / nrow
    top = 400
    botm = [220, 200, np.random.random((nrow, ncol))]

    # create a dummy dis package for gridgen
    ms = flopy.modflow.Modflow()
    dis5 = flopy.modflow.ModflowDis(ms, nlay=nlay, nrow=nrow, ncol=ncol,
                                    delr=delr,
                                    delc=delc, top=top, botm=botm)

    gridgen_ws = cpth
    g = Gridgen(dis5, model_ws=gridgen_ws, exe_name=exe_name)

    rf0shp = os.path.join(gridgen_ws, 'rf0')
    xmin = 7 * delr
    xmax = 12 * delr
    ymin = 8 * delc
    ymax = 13 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax),
                (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 1, range(nlay))

    rf1shp = os.path.join(gridgen_ws, 'rf1')
    xmin = 8 * delr
    xmax = 11 * delr
    ymin = 9 * delc
    ymax = 12 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax),
                (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 2, range(nlay))

    rf2shp = os.path.join(gridgen_ws, 'rf2')
    xmin = 9 * delr
    xmax = 10 * delr
    ymin = 10 * delc
    ymax = 11 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax),
                (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 3, range(nlay))

    # if gridgen executable is available then do the main part of the test
    if run:

        # Use gridgen to build the grid
        g.build()

        # test the different gridprops dictionaries, which contain all the
        # information needed to make the different discretization packages
        gridprops = g.get_gridprops_disv()
        gridprops = g.get_gridprops()
        #gridprops = g.get_gridprops_disu6()

        # test the gridgen point intersection
        points = [(4750., 5250.)]
        cells = g.intersect(points, 'point', 0)
        n = cells['nodenumber'][0]
        msg = ('gridgen point intersect did not identify the correct '
               'cell {} <> {}'.format(n, 308))
        assert n == 308, msg

        # test the gridgen line intersection
        line = [[[(Lx, Ly), (Lx, 0.)]]]
        cells = g.intersect(line, 'line', 0)
        nlist = [n for n in cells['nodenumber']]
        nlist2 = [19, 650, 39, 630, 59, 610, 79, 590, 99, 570, 119, 550, 139,
                  530, 159, 510, 194, 490, 265, 455, 384]
        msg = ('gridgen line intersect did not identify the correct '
               'cells {} <> {}'.format(nlist, nlist2))
        assert nlist == nlist2, msg

        # test getting a modflow-usg disu package
        mu = flopy.modflow.Modflow(version='mfusg', structured=False)
        disu = g.get_disu(mu)

    return
Ejemplo n.º 10
0
def test_gridgen():

    # define the base grid and then create a couple levels of nested
    # refinement
    Lx = 10000.
    Ly = 10500.
    nlay = 3
    nrow = 21
    ncol = 20
    delr = Lx / ncol
    delc = Ly / nrow
    top = 400
    botm = [220, 200, np.random.random((nrow, ncol))]

    # create a dummy dis package for gridgen
    ms = flopy.modflow.Modflow()
    dis5 = flopy.modflow.ModflowDis(ms,
                                    nlay=nlay,
                                    nrow=nrow,
                                    ncol=ncol,
                                    delr=delr,
                                    delc=delc,
                                    top=top,
                                    botm=botm)

    gridgen_ws = cpth
    g = Gridgen(dis5, model_ws=gridgen_ws, exe_name=exe_name)

    rf0shp = os.path.join(gridgen_ws, 'rf0')
    xmin = 7 * delr
    xmax = 12 * delr
    ymin = 8 * delc
    ymax = 13 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax),
                (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 1, range(nlay))

    rf1shp = os.path.join(gridgen_ws, 'rf1')
    xmin = 8 * delr
    xmax = 11 * delr
    ymin = 9 * delc
    ymax = 12 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax),
                (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 2, range(nlay))

    rf2shp = os.path.join(gridgen_ws, 'rf2')
    xmin = 9 * delr
    xmax = 10 * delr
    ymin = 10 * delc
    ymax = 11 * delc
    rfpoly = [[[(xmin, ymin), (xmax, ymin), (xmax, ymax), (xmin, ymax),
                (xmin, ymin)]]]
    g.add_refinement_features(rfpoly, 'polygon', 3, range(nlay))

    # if gridgen executable is available then do the main part of the test
    if run:

        # Use gridgen to build the grid
        g.build()

        # test the different gridprops dictionaries, which contain all the
        # information needed to make the different discretization packages
        gridprops = g.get_gridprops_disv()
        gridprops = g.get_gridprops()
        #gridprops = g.get_gridprops_disu6()

        # test the gridgen point intersection
        points = [(4750., 5250.)]
        cells = g.intersect(points, 'point', 0)
        n = cells['nodenumber'][0]
        msg = ('gridgen point intersect did not identify the correct '
               'cell {} <> {}'.format(n, 308))
        assert n == 308, msg

        # test the gridgen line intersection
        line = [[[(Lx, Ly), (Lx, 0.)]]]
        cells = g.intersect(line, 'line', 0)
        nlist = [n for n in cells['nodenumber']]
        nlist2 = [
            19, 650, 39, 630, 59, 610, 79, 590, 99, 570, 119, 550, 139, 530,
            159, 510, 194, 490, 265, 455, 384
        ]
        msg = ('gridgen line intersect did not identify the correct '
               'cells {} <> {}'.format(nlist, nlist2))
        assert nlist == nlist2, msg

        # test getting a modflow-usg disu package
        mu = flopy.modflow.Modflow(version='mfusg', structured=False)
        disu = g.get_disu(mu)

    return
Ejemplo n.º 11
0
    shpnames_dic['river']: 'line',
    shpnames_dic['ghb']: 'line',
    shpnames_dic['active']: 'polygon'
}

# ---- Create main dictionary
icpl_dic = {}

# ----| Start interceptions for all boundaries with gridgen mesh |----
for inter_id in inter_list:
    # ---- Fetch shp path without '.shp'
    shp_id = shpnames_dic[inter_id].replace('.shp', '')
    # ---- Fetch shp type
    feat_type = geoms_dic[shpnames_dic[inter_id]]
    # ---- Perform intersection and convert into dataframe
    df = pd.DataFrame(g.intersect(shp_id, feat_type, nlay - 1))
    # ---- Drop duplicated node during intersection
    df.drop_duplicates(subset='nodenumber',
                       keep='first',
                       inplace=True,
                       ignore_index=True)
    # ---- Decode the 'ID' column into utf-8
    df['ID'] = [x.decode('utf-8') for x in df['ID']]
    # ---- Fetch ID column  cataegories
    feat_ids = pd.Categorical(df['ID']).categories
    # ---- Manage bad intersection
    df = df.query('nodenumber > 0')
    # ---- Compute river curvilinear length for river purpose
    if inter_id.startswith('river'):

        # ---- Compute curvilinea distance xc