Пример #1
0
def build_model(idx, dir):
    nlay, nrow, ncol = 1, 1, 3
    nper = 1
    perlen = [1.0]
    nstp = [1]
    tsmult = [1.0]
    steady = [True]
    delr = 1.0
    delc = 1.0
    top = 1.0
    laytyp = 0
    ss = 0.0
    sy = 0.1
    botm = [0.0]
    strt = 1.0
    hnoflo = 1e30
    hdry = -1e30
    hk = 1.0

    nouter, ninner = 100, 300
    hclose, rclose, relax = 1e-6, 1e-6, 1.0

    tdis_rc = []
    for i in range(nper):
        tdis_rc.append((perlen[i], nstp[i], tsmult[i]))

    name = ex[idx]

    # build MODFLOW 6 files
    ws = dir
    sim = flopy.mf6.MFSimulation(
        sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws
    )
    # create tdis package
    tdis = flopy.mf6.ModflowTdis(
        sim, time_units="DAYS", nper=nper, perioddata=tdis_rc
    )

    # create gwt model
    gwtname = "gwt_" + name
    gwt = flopy.mf6.MFModel(
        sim,
        model_type="gwt6",
        modelname=gwtname,
        model_nam_file="{}.nam".format(gwtname),
    )
    gwt.name_file.save_flows = True

    # create iterative model solution and register the gwt model with it
    imsgwt = flopy.mf6.ModflowIms(
        sim,
        print_option="SUMMARY",
        outer_dvclose=hclose,
        outer_maximum=nouter,
        under_relaxation="NONE",
        inner_maximum=ninner,
        inner_dvclose=hclose,
        rcloserecord=rclose,
        linear_acceleration="BICGSTAB",
        scaling_method="NONE",
        reordering_method="NONE",
        relaxation_factor=relax,
        filename="{}.ims".format(gwtname),
    )
    sim.register_ims_package(imsgwt, [gwt.name])

    dis = flopy.mf6.ModflowGwtdis(
        gwt,
        nlay=nlay,
        nrow=nrow,
        ncol=ncol,
        delr=delr,
        delc=delc,
        top=top,
        botm=botm,
        idomain=1,
        filename="{}.dis".format(gwtname),
    )

    # initial conditions
    ic = flopy.mf6.ModflowGwtic(
        gwt, strt=10.0, filename="{}.ic".format(gwtname)
    )

    # advection
    adv = flopy.mf6.ModflowGwtadv(gwt)

    # mass storage and transfer
    mst = flopy.mf6.ModflowGwtmst(gwt, porosity=0.1)

    # output control
    oc = flopy.mf6.ModflowGwtoc(
        gwt,
        budget_filerecord="{}.cbc".format(gwtname),
        concentration_filerecord="{}.ucn".format(gwtname),
        concentrationprintrecord=[
            ("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")
        ],
        saverecord=[("CONCENTRATION", "LAST"), ("BUDGET", "LAST")],
        printrecord=[("CONCENTRATION", "LAST"), ("BUDGET", "LAST")],
    )

    # create a heads file with head equal top
    fname = os.path.join(ws, "myhead.hds")
    with open(fname, "wb") as fbin:
        for kstp in range(nstp[0]):
            write_head(fbin, top * np.ones((nrow, ncol)), kstp=kstp + 1)

    # create a budget file
    qx = 0.0
    qy = 0.0
    qz = 0.0
    shape = (nlay, nrow, ncol)
    spdis, flowja = uniform_flow_field(qx, qy, qz, shape)
    dt = np.dtype(
        [
            ("ID1", np.int32),
            ("ID2", np.int32),
            ("FLOW", np.float64),
            ("CONCENTRATION", np.float64),
        ]
    )
    print(flowja)
    # create unbalanced flowja to check flow_imbalance_correction
    # note that residual must be stored in diagonal position
    flowja = np.array([0.01, 0.01, -0.01, 0.0, -0.01, 0.01, 0.01])

    dt = np.dtype(
        [
            ("ID1", np.int32),
            ("ID2", np.int32),
            ("FLOW", np.float64),
            ("SATURATION", np.float64),
        ]
    )
    sat = np.array(
        [(i, i, 0.0, 1.0) for i in range(nlay * nrow * ncol)], dtype=dt
    )

    fname = os.path.join(ws, "mybudget.bud")
    with open(fname, "wb") as fbin:
        for kstp in range(nstp[0]):
            write_budget(fbin, flowja, kstp=kstp + 1)
            write_budget(
                fbin, spdis, text="      DATA-SPDIS", imeth=6, kstp=kstp + 1
            )
            write_budget(
                fbin, sat, text="        DATA-SAT", imeth=6, kstp=kstp + 1
            )
    fbin.close()

    # flow model interface
    packagedata = [
        ("GWFBUDGET", "mybudget.bud", None),
        ("GWFHEAD", "myhead.hds", None),
    ]
    fmi = flopy.mf6.ModflowGwtfmi(
        gwt, flow_imbalance_correction=True, packagedata=packagedata
    )

    return sim, None
Пример #2
0
def get_model(idx, dir):
    nlay, nrow, ncol = 1, 1, 101
    perlen = [160., 1340.]
    nper = len(perlen)
    tslength = 10.
    nstp = [p / tslength for p in perlen]
    tsmult = nper * [1.]
    delr = 0.16
    delc = 0.16
    top = 1.
    botm = 0.
    velocity = 0.1
    porosity = 0.37
    bulk_density = 1.587
    dispersivity = 1.0
    source_concentration = 0.05
    specific_discharge = velocity * porosity
    inflow_rate = specific_discharge * delc * (top - botm)

    nouter, ninner = 100, 300
    hclose, rclose, relax = 1e-6, 1e-6, 1.

    tdis_rc = []
    for i in range(nper):
        tdis_rc.append((perlen[i], nstp[i], tsmult[i]))

    name = ex[idx]

    # build MODFLOW 6 files
    ws = dir
    sim = flopy.mf6.MFSimulation(sim_name=name,
                                 version='mf6',
                                 exe_name='mf6',
                                 sim_ws=ws)
    # create tdis package
    tdis = flopy.mf6.ModflowTdis(sim,
                                 time_units='SECONDS',
                                 nper=nper,
                                 perioddata=tdis_rc)

    # create gwt model
    gwtname = 'gwt_' + name
    gwt = flopy.mf6.MFModel(sim,
                            model_type='gwt6',
                            modelname=gwtname,
                            model_nam_file='{}.nam'.format(gwtname))
    gwt.name_file.save_flows = True

    # create iterative model solution and register the gwt model with it
    imsgwt = flopy.mf6.ModflowIms(sim,
                                  print_option='SUMMARY',
                                  outer_dvclose=hclose,
                                  outer_maximum=nouter,
                                  under_relaxation='NONE',
                                  inner_maximum=ninner,
                                  inner_dvclose=hclose,
                                  rcloserecord=rclose,
                                  linear_acceleration='BICGSTAB',
                                  scaling_method='NONE',
                                  reordering_method='NONE',
                                  relaxation_factor=relax,
                                  filename='{}.ims'.format(gwtname))
    sim.register_ims_package(imsgwt, [gwt.name])

    dis = flopy.mf6.ModflowGwtdis(gwt,
                                  nlay=nlay,
                                  nrow=nrow,
                                  ncol=ncol,
                                  delr=delr,
                                  delc=delc,
                                  top=top,
                                  botm=botm)
    ic = flopy.mf6.ModflowGwtic(gwt, strt=0.)
    adv = flopy.mf6.ModflowGwtadv(gwt, scheme="TVD")
    dsp = flopy.mf6.ModflowGwtdsp(gwt,
                                  xt3d_off=True,
                                  alh=dispersivity,
                                  ath1=dispersivity)
    mst = flopy.mf6.ModflowGwtmst(gwt,
                                  sorption=isotherm[idx],
                                  porosity=porosity,
                                  bulk_density=bulk_density,
                                  distcoef=distcoef[idx],
                                  sp2=sp2[idx])

    # sources
    sourcerecarray = [('WEL-1', 'AUX', 'CONCENTRATION')]
    ssm = flopy.mf6.ModflowGwtssm(gwt, sources=sourcerecarray)

    # create a heads file with head equal top
    fname = os.path.join(ws, 'myhead.hds')
    with open(fname, 'wb') as fbin:
        kstp = 0
        totim = 0
        for kper in range(nper):
            totim += perlen[kper]
            write_head(fbin,
                       top * np.ones((nrow, ncol)),
                       kstp=kstp + 1,
                       kper=kper + 1,
                       pertim=perlen[kper],
                       totim=totim)

    # create a budget file
    qx = specific_discharge
    qy = 0.
    qz = 0.
    shape = (nlay, nrow, ncol)
    spdis, flowja = uniform_flow_field(qx, qy, qz, shape, delr=delr, delc=delc)
    dt = np.dtype([
        ('ID1', np.int32),
        ('ID2', np.int32),
        ('FLOW', np.float64),
        ('CONCENTRATION', np.float64),
    ])
    wel = [
        np.array([(0 + 1, 0 + 1, inflow_rate, source_concentration)],
                 dtype=dt),
        np.array([(0 + 1, 0 + 1, inflow_rate, 0.)], dtype=dt)
    ]
    chd = np.array([(ncol - 1 + 1, ncol - 1 + 1, -inflow_rate, 0.)], dtype=dt)

    dt = np.dtype([
        ('ID1', np.int32),
        ('ID2', np.int32),
        ('FLOW', np.float64),
        ('SATURATION', np.float64),
    ])
    sat = np.array([(i, i, 0., 1.) for i in range(nlay * nrow * ncol)],
                   dtype=dt)

    fname = os.path.join(ws, 'mybudget.bud')
    with open(fname, 'wb') as fbin:
        kstp = 0
        totim = 0
        for kper in range(nper):
            totim += perlen[kper]
            delt = perlen[kper] / nstp[kper]
            write_budget(fbin,
                         flowja,
                         kstp=kstp + 1,
                         kper=kper + 1,
                         pertim=perlen[kper],
                         totim=totim,
                         delt=delt)
            write_budget(fbin,
                         spdis,
                         text='      DATA-SPDIS',
                         imeth=6,
                         kstp=kstp + 1,
                         kper=kper + 1,
                         pertim=perlen[kper],
                         totim=totim,
                         delt=delt)
            write_budget(fbin,
                         sat,
                         text='        DATA-SAT',
                         imeth=6,
                         kstp=kstp + 1,
                         kper=kper + 1,
                         pertim=perlen[kper],
                         totim=totim,
                         delt=delt)
            write_budget(fbin,
                         wel[kper],
                         text='             WEL',
                         imeth=6,
                         text2id2='           WEL-1',
                         kstp=kstp + 1,
                         kper=kper + 1,
                         pertim=perlen[kper],
                         totim=totim,
                         delt=delt)
            write_budget(fbin,
                         chd,
                         text='             CHD',
                         imeth=6,
                         text2id2='           CHD-1',
                         kstp=kstp + 1,
                         kper=kper + 1,
                         pertim=perlen[kper],
                         totim=totim,
                         delt=delt)
    fbin.close()

    # flow model interface
    packagedata = [('GWFBUDGET', 'mybudget.bud', None),
                   ('GWFHEAD', 'myheads.hds', None)]
    fmi = flopy.mf6.ModflowGwtfmi(gwt, packagedata=packagedata)

    # output control
    oc = flopy.mf6.ModflowGwtoc(
        gwt,
        budget_filerecord='{}.cbc'.format(gwtname),
        concentration_filerecord='{}.ucn'.format(gwtname),
        concentrationprintrecord=[('COLUMNS', 10, 'WIDTH', 15, 'DIGITS', 6,
                                   'GENERAL')],
        saverecord=[('CONCENTRATION', 'LAST'), ('BUDGET', 'LAST')],
        printrecord=[('CONCENTRATION', 'LAST'), ('BUDGET', 'LAST')])

    obs_data = {
        'conc_obs.csv': [
            ('X008', 'CONCENTRATION', (0, 0, 50)),
        ]
    }

    obs_package = flopy.mf6.ModflowUtlobs(gwt,
                                          pname='conc_obs',
                                          filename='{}.obs'.format(gwtname),
                                          digits=10,
                                          print_input=True,
                                          continuous=obs_data)

    return sim
Пример #3
0
def get_model(idx, dir):
    nlay, nrow, ncol = 1, 1, 100
    nper = 1
    perlen = [5.0]
    nstp = [200]
    tsmult = [1.0]
    steady = [True]
    delr = 1.0
    delc = 1.0
    top = 1.0
    laytyp = 0
    ss = 0.0
    sy = 0.1
    botm = [0.0]
    strt = 1.0
    hnoflo = 1e30
    hdry = -1e30
    hk = 1.0

    c = {0: [[(0, 0, 0), 0.0000000], [(0, 0, 99), 0.0000000]]}

    nouter, ninner = 100, 300
    hclose, rclose, relax = 1e-6, 1e-6, 1.0

    tdis_rc = []
    for i in range(nper):
        tdis_rc.append((perlen[i], nstp[i], tsmult[i]))

    name = ex[idx]

    # build MODFLOW 6 files
    ws = dir
    sim = flopy.mf6.MFSimulation(sim_name=name,
                                 version="mf6",
                                 exe_name="mf6",
                                 sim_ws=ws)
    # create tdis package
    tdis = flopy.mf6.ModflowTdis(sim,
                                 time_units="DAYS",
                                 nper=nper,
                                 perioddata=tdis_rc)

    # create gwt model
    gwtname = "gwt_" + name
    gwt = flopy.mf6.MFModel(
        sim,
        model_type="gwt6",
        modelname=gwtname,
        model_nam_file="{}.nam".format(gwtname),
    )
    gwt.name_file.save_flows = True

    # create iterative model solution and register the gwt model with it
    imsgwt = flopy.mf6.ModflowIms(
        sim,
        print_option="SUMMARY",
        outer_dvclose=hclose,
        outer_maximum=nouter,
        under_relaxation="NONE",
        inner_maximum=ninner,
        inner_dvclose=hclose,
        rcloserecord=rclose,
        linear_acceleration="BICGSTAB",
        scaling_method="NONE",
        reordering_method="NONE",
        relaxation_factor=relax,
        filename="{}.ims".format(gwtname),
    )
    sim.register_ims_package(imsgwt, [gwt.name])

    dis = flopy.mf6.ModflowGwtdis(
        gwt,
        nlay=nlay,
        nrow=nrow,
        ncol=ncol,
        delr=delr,
        delc=delc,
        top=top,
        botm=botm,
        idomain=1,
        filename="{}.dis".format(gwtname),
    )

    # initial conditions
    ic = flopy.mf6.ModflowGwtic(gwt,
                                strt=0.0,
                                filename="{}.ic".format(gwtname))

    # dispersion
    xt3d_off = not xt3d[idx]
    dsp = flopy.mf6.ModflowGwtdsp(
        gwt,
        xt3d_off=xt3d_off,
        diffc=100.0,
        alh=0.0,
        alv=0.0,
        ath1=0.0,
        atv=0.0,
        filename="{}.dsp".format(gwtname),
    )

    # constant concentration
    cncs = {0: [[(0, 0, 0), 1.0]]}
    cnc = flopy.mf6.ModflowGwtcnc(
        gwt,
        maxbound=len(cncs),
        stress_period_data=cncs,
        save_flows=False,
        pname="CNC-1",
    )

    # mass storage and transfer
    mst = flopy.mf6.ModflowGwtmst(gwt, porosity=0.1)

    # create a heads file with head equal top
    fname = os.path.join(ws, "myhead.hds")
    with open(fname, "wb") as fbin:
        for kstp in range(1):  # nstp[0]):
            write_head(fbin, top * np.ones((nrow, ncol)), kstp=kstp + 1)

    # create a budget file with flows set to zero
    nja = (ncol - 2) * 3 + 2 * 2
    flowja = np.zeros(nja, dtype=np.float64)

    dt = np.dtype([
        ("id1", np.int32),
        ("id2", np.int32),
        ("flow", np.float64),
        ("qx", np.float64),
        ("qy", np.float64),
        ("qz", np.float64),
    ])
    spdis = np.array([(id1, id1, 0.0, 0.0, 0.0, 0.0) for id1 in range(100)],
                     dtype=dt)

    dt = np.dtype([
        ("ID1", np.int32),
        ("ID2", np.int32),
        ("FLOW", np.float64),
        ("SATURATION", np.float64),
    ])
    sat = np.array([(i, i, 0.0, 1.0) for i in range(nlay * nrow * ncol)],
                   dtype=dt)

    fname = os.path.join(ws, "mybudget.bud")
    with open(fname, "wb") as fbin:
        for kstp in range(1):  # nstp[0]):
            write_budget(fbin, flowja, kstp=kstp + 1)
            write_budget(fbin,
                         spdis,
                         text="      DATA-SPDIS",
                         imeth=6,
                         kstp=kstp + 1)
            write_budget(fbin,
                         sat,
                         text="        DATA-SAT",
                         imeth=6,
                         kstp=kstp + 1)
    fbin.close()

    # flow model interface
    packagedata = [
        ("GWFBUDGET", "mybudget.bud", None),
        ("GWFHEAD", "myheads.hds", None),
    ]
    fmi = flopy.mf6.ModflowGwtfmi(gwt, packagedata=packagedata)

    # output control
    oc = flopy.mf6.ModflowGwtoc(
        gwt,
        budget_filerecord="{}.cbc".format(gwtname),
        concentration_filerecord="{}.ucn".format(gwtname),
        concentrationprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6,
                                   "GENERAL")],
        saverecord=[("CONCENTRATION", "LAST"), ("BUDGET", "LAST")],
        printrecord=[("CONCENTRATION", "LAST"), ("BUDGET", "LAST")],
    )

    return sim
Пример #4
0
def build_model(idx, dir):
    nlay, nrow, ncol = 1, 1, 100
    nper = 1
    perlen = [5.0]
    nstp = [200]
    tsmult = [1.0]
    steady = [True]
    delr = 1.0
    delc = 1.0
    top = 1.0
    botm = [0.0]
    strt = 1.0
    hk = 1.0
    laytyp = 0

    nouter, ninner = 100, 300
    hclose, rclose, relax = 1e-6, 1e-6, 1.0

    tdis_rc = []
    for i in range(nper):
        tdis_rc.append((perlen[i], nstp[i], tsmult[i]))

    name = ex[idx]

    # build MODFLOW 6 files
    ws = dir
    sim = flopy.mf6.MFSimulation(sim_name=name,
                                 version="mf6",
                                 exe_name="mf6",
                                 sim_ws=ws)
    # create tdis package
    tdis = flopy.mf6.ModflowTdis(sim,
                                 time_units="DAYS",
                                 nper=nper,
                                 perioddata=tdis_rc)

    # create gwt model
    gwtname = "gwt_" + name
    gwt = flopy.mf6.MFModel(
        sim,
        model_type="gwt6",
        modelname=gwtname,
        model_nam_file="{}.nam".format(gwtname),
    )
    gwt.name_file.save_flows = True

    # create iterative model solution and register the gwt model with it
    imsgwt = flopy.mf6.ModflowIms(
        sim,
        print_option="SUMMARY",
        outer_dvclose=hclose,
        outer_maximum=nouter,
        under_relaxation="NONE",
        inner_maximum=ninner,
        inner_dvclose=hclose,
        rcloserecord=rclose,
        linear_acceleration="BICGSTAB",
        scaling_method="NONE",
        reordering_method="NONE",
        relaxation_factor=relax,
        filename="{}.ims".format(gwtname),
    )
    sim.register_ims_package(imsgwt, [gwt.name])

    dis = flopy.mf6.ModflowGwtdis(
        gwt,
        nlay=nlay,
        nrow=nrow,
        ncol=ncol,
        delr=delr,
        delc=delc,
        top=top,
        botm=botm,
        idomain=1,
        filename="{}.dis".format(gwtname),
    )

    # initial conditions
    ic = flopy.mf6.ModflowGwtic(gwt,
                                strt=0.0,
                                filename="{}.ic".format(gwtname))

    # advection
    adv = flopy.mf6.ModflowGwtadv(gwt,
                                  scheme=scheme[idx],
                                  filename="{}.adv".format(gwtname))

    # mass storage and transfer
    mst = flopy.mf6.ModflowGwtmst(gwt, porosity=0.1)

    # sources
    sourcerecarray = [("WEL-1", "AUX", "CONCENTRATION")]
    ssm = flopy.mf6.ModflowGwtssm(gwt,
                                  sources=sourcerecarray,
                                  filename="{}.ssm".format(gwtname))

    # create a heads file with head equal top
    fname = os.path.join(ws, "myhead.hds")
    with open(fname, "wb") as fbin:
        for kstp in range(1):  # nstp[0]):
            write_head(fbin, top * np.ones((nrow, ncol)), kstp=kstp + 1)

    # create a budget file
    qx = 1.0
    qy = 0.0
    qz = 0.0
    shape = (nlay, nrow, ncol)
    spdis, flowja = uniform_flow_field(qx, qy, qz, shape)
    dt = np.dtype([
        ("ID1", np.int32),
        ("ID2", np.int32),
        ("FLOW", np.float64),
        ("CONCENTRATION", np.float64),
    ])
    wel = np.array([(0 + 1, 0 + 1, 1.0, 1.0)], dtype=dt)
    chd = np.array([(ncol - 1 + 1, 0 + 1, -1.0, 0.0)], dtype=dt)

    dt = np.dtype([
        ("ID1", np.int32),
        ("ID2", np.int32),
        ("FLOW", np.float64),
        ("SATURATION", np.float64),
    ])
    sat = np.array([(i, i, 0.0, 1.0) for i in range(nlay * nrow * ncol)],
                   dtype=dt)

    fname = os.path.join(ws, "mybudget.bud")
    with open(fname, "wb") as fbin:
        for kstp in range(1):  # nstp[0]):
            write_budget(fbin, flowja, kstp=kstp + 1)
            write_budget(fbin,
                         spdis,
                         text="      DATA-SPDIS",
                         imeth=6,
                         kstp=kstp + 1)
            write_budget(fbin,
                         sat,
                         text="        DATA-SAT",
                         imeth=6,
                         kstp=kstp + 1)
            write_budget(
                fbin,
                wel,
                text="             WEL",
                imeth=6,
                text2id2="           WEL-1",
                kstp=kstp + 1,
            )
            write_budget(
                fbin,
                chd,
                text="             CHD",
                imeth=6,
                text2id2="           CHD-1",
                kstp=kstp + 1,
            )
    fbin.close()

    # flow model interface
    packagedata = [
        ("GWFBUDGET", "mybudget.bud", None),
        ("GWFHEAD", "myhead.hds", None),
    ]
    fmi = flopy.mf6.ModflowGwtfmi(gwt, packagedata=packagedata)

    # output control
    oc = flopy.mf6.ModflowGwtoc(
        gwt,
        budget_filerecord="{}.cbc".format(gwtname),
        concentration_filerecord="{}.ucn".format(gwtname),
        concentrationprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6,
                                   "GENERAL")],
        saverecord=[("CONCENTRATION", "LAST"), ("BUDGET", "LAST")],
        printrecord=[("CONCENTRATION", "LAST"), ("BUDGET", "LAST")],
    )

    obs_data = {
        "conc_obs.csv": [
            ("(1-1-10)", "CONCENTRATION", (0, 0, 9)),
            ("(1-1-50)", "CONCENTRATION", (0, 0, 49)),
        ],
        "flow_obs.csv": [
            ("c10-c11", "FLOW-JA-FACE", (0, 0, 9), (0, 0, 10)),
            ("c50-c51", "FLOW-JA-FACE", (0, 0, 49), (0, 0, 50)),
            ("c99-c100", "FLOW-JA-FACE", (0, 0, 98), (0, 0, 99)),
        ],
    }

    obs_package = flopy.mf6.ModflowUtlobs(
        gwt,
        pname="conc_obs",
        filename="{}.obs".format(gwtname),
        digits=10,
        print_input=True,
        continuous=obs_data,
    )

    return sim, None
Пример #5
0
def get_model(idx, dir):
    nlay, nrow, ncol = 1, 1, 100
    nper = 1
    perlen = [5.0]
    nstp = [200]
    tsmult = [1.]
    steady = [True]
    delr = 1.
    delc = 1.
    top = 1.
    laytyp = 0
    ss = 0.
    sy = 0.1
    botm = [0.]
    strt = 1.
    hnoflo = 1e30
    hdry = -1e30
    hk = 1.0

    c = {0: [[(0, 0, 0), 0.0000000], [(0, 0, 99), 0.0000000]]}

    nouter, ninner = 100, 300
    hclose, rclose, relax = 1e-6, 1e-6, 1.

    tdis_rc = []
    for i in range(nper):
        tdis_rc.append((perlen[i], nstp[i], tsmult[i]))

    name = ex[idx]

    # build MODFLOW 6 files
    ws = dir
    sim = flopy.mf6.MFSimulation(sim_name=name,
                                 version='mf6',
                                 exe_name='mf6',
                                 sim_ws=ws)
    # create tdis package
    tdis = flopy.mf6.ModflowTdis(sim,
                                 time_units='DAYS',
                                 nper=nper,
                                 perioddata=tdis_rc)

    # create gwt model
    gwtname = 'gwt_' + name
    gwt = flopy.mf6.MFModel(sim,
                            model_type='gwt6',
                            modelname=gwtname,
                            model_nam_file='{}.nam'.format(gwtname))
    gwt.name_file.save_flows = True

    # create iterative model solution and register the gwt model with it
    imsgwt = flopy.mf6.ModflowIms(sim,
                                  print_option='SUMMARY',
                                  outer_dvclose=hclose,
                                  outer_maximum=nouter,
                                  under_relaxation='NONE',
                                  inner_maximum=ninner,
                                  inner_dvclose=hclose,
                                  rcloserecord=rclose,
                                  linear_acceleration='BICGSTAB',
                                  scaling_method='NONE',
                                  reordering_method='NONE',
                                  relaxation_factor=relax,
                                  filename='{}.ims'.format(gwtname))
    sim.register_ims_package(imsgwt, [gwt.name])

    dis = flopy.mf6.ModflowGwtdis(gwt,
                                  nlay=nlay,
                                  nrow=nrow,
                                  ncol=ncol,
                                  delr=delr,
                                  delc=delc,
                                  top=top,
                                  botm=botm,
                                  idomain=1,
                                  filename='{}.dis'.format(gwtname))

    # initial conditions
    ic = flopy.mf6.ModflowGwtic(gwt, strt=0., filename='{}.ic'.format(gwtname))

    # dispersion
    xt3d_off = not xt3d[idx]
    dsp = flopy.mf6.ModflowGwtdsp(gwt,
                                  xt3d_off=xt3d_off,
                                  diffc=100.,
                                  alh=0.,
                                  alv=0.,
                                  ath1=0.,
                                  atv=0.,
                                  filename='{}.dsp'.format(gwtname))

    # constant concentration
    cncs = {0: [[(0, 0, 0), 1.0]]}
    cnc = flopy.mf6.ModflowGwtcnc(gwt,
                                  maxbound=len(cncs),
                                  stress_period_data=cncs,
                                  save_flows=False,
                                  pname='CNC-1')

    # mass storage and transfer
    mst = flopy.mf6.ModflowGwtmst(gwt, porosity=0.1)

    # create a heads file with head equal top
    fname = os.path.join(ws, 'myhead.hds')
    with open(fname, 'wb') as fbin:
        for kstp in range(1):  #nstp[0]):
            write_head(fbin, top * np.ones((nrow, ncol)), kstp=kstp + 1)

    # create a budget file with flows set to zero
    nja = (ncol - 2) * 3 + 2 * 2
    flowja = np.zeros(nja, dtype=np.float64)

    dt = np.dtype([
        ('id1', np.int32),
        ('id2', np.int32),
        ('flow', np.float64),
        ('qx', np.float64),
        ('qy', np.float64),
        ('qz', np.float64),
    ])
    spdis = np.array([(id1, id1, 0., 0., 0., 0.) for id1 in range(100)],
                     dtype=dt)

    dt = np.dtype([
        ('ID1', np.int32),
        ('ID2', np.int32),
        ('FLOW', np.float64),
        ('SATURATION', np.float64),
    ])
    sat = np.array([(i, i, 0., 1.) for i in range(nlay * nrow * ncol)],
                   dtype=dt)

    fname = os.path.join(ws, 'mybudget.bud')
    with open(fname, 'wb') as fbin:
        for kstp in range(1):  #nstp[0]):
            write_budget(fbin, flowja, kstp=kstp + 1)
            write_budget(fbin,
                         spdis,
                         text='      DATA-SPDIS',
                         imeth=6,
                         kstp=kstp + 1)
            write_budget(fbin,
                         sat,
                         text='        DATA-SAT',
                         imeth=6,
                         kstp=kstp + 1)
    fbin.close()

    # flow model interface
    packagedata = [('GWFBUDGET', 'mybudget.bud', None),
                   ('GWFHEAD', 'myheads.hds', None)]
    fmi = flopy.mf6.ModflowGwtfmi(gwt, packagedata=packagedata)

    # output control
    oc = flopy.mf6.ModflowGwtoc(
        gwt,
        budget_filerecord='{}.cbc'.format(gwtname),
        concentration_filerecord='{}.ucn'.format(gwtname),
        concentrationprintrecord=[('COLUMNS', 10, 'WIDTH', 15, 'DIGITS', 6,
                                   'GENERAL')],
        saverecord=[('CONCENTRATION', 'LAST'), ('BUDGET', 'LAST')],
        printrecord=[('CONCENTRATION', 'LAST'), ('BUDGET', 'LAST')])

    return sim
Пример #6
0
def get_model(idx, dir):
    nlay, nrow, ncol = 1, 1, 100
    nper = 1
    perlen = [5.0]
    nstp = [200]
    tsmult = [1.]
    steady = [True]
    delr = 1.
    delc = 1.
    top = 1.
    botm = [0.]
    strt = 1.
    hk = 1.0
    laytyp = 0

    nouter, ninner = 100, 300
    hclose, rclose, relax = 1e-6, 1e-6, 1.

    tdis_rc = []
    for i in range(nper):
        tdis_rc.append((perlen[i], nstp[i], tsmult[i]))

    name = ex[idx]

    # build MODFLOW 6 files
    ws = dir
    sim = flopy.mf6.MFSimulation(sim_name=name, version='mf6',
                                 exe_name='mf6',
                                 sim_ws=ws)
    # create tdis package
    tdis = flopy.mf6.ModflowTdis(sim, time_units='DAYS',
                                 nper=nper, perioddata=tdis_rc)

    # create gwt model
    gwtname = 'gwt_' + name
    gwt = flopy.mf6.MFModel(sim, model_type='gwt6', modelname=gwtname,
                            model_nam_file='{}.nam'.format(gwtname))
    gwt.name_file.save_flows = True

    # create iterative model solution and register the gwt model with it
    imsgwt = flopy.mf6.ModflowIms(sim, print_option='SUMMARY',
                                  outer_dvclose=hclose,
                                  outer_maximum=nouter,
                                  under_relaxation='NONE',
                                  inner_maximum=ninner,
                                  inner_dvclose=hclose, rcloserecord=rclose,
                                  linear_acceleration='BICGSTAB',
                                  scaling_method='NONE',
                                  reordering_method='NONE',
                                  relaxation_factor=relax,
                                  filename='{}.ims'.format(gwtname))
    sim.register_ims_package(imsgwt, [gwt.name])

    dis = flopy.mf6.ModflowGwtdis(gwt, nlay=nlay, nrow=nrow, ncol=ncol,
                                  delr=delr, delc=delc,
                                  top=top, botm=botm,
                                  idomain=1,
                                  filename='{}.dis'.format(gwtname))

    # initial conditions
    ic = flopy.mf6.ModflowGwtic(gwt, strt=0.,
                                filename='{}.ic'.format(gwtname))

    # advection
    adv = flopy.mf6.ModflowGwtadv(gwt, scheme=scheme[idx],
                                filename='{}.adv'.format(gwtname))

    # mass storage and transfer
    mst = flopy.mf6.ModflowGwtmst(gwt, porosity=0.1)

    # sources
    sourcerecarray = [('WEL-1', 'AUX', 'CONCENTRATION')]
    ssm = flopy.mf6.ModflowGwtssm(gwt, sources=sourcerecarray,
                                filename='{}.ssm'.format(gwtname))

    # create a heads file with head equal top
    fname = os.path.join(ws, 'myhead.hds')
    with open(fname, 'wb') as fbin:
        for kstp in range(1): #nstp[0]):
            write_head(fbin, top * np.ones((nrow, ncol)), kstp=kstp + 1)


    # create a budget file
    qx = 1.
    qy = 0.
    qz = 0.
    shape = (nlay, nrow, ncol)
    spdis, flowja = uniform_flow_field(qx, qy, qz, shape)
    dt = np.dtype([('ID1', np.int32),
                   ('ID2', np.int32),
                   ('FLOW', np.float64),
                   ('CONCENTRATION', np.float64),
                   ])
    wel = np.array([(0 + 1, 0 + 1, 1., 1.)], dtype=dt)
    chd = np.array([(ncol - 1 + 1, 0 + 1, -1., 0.)], dtype=dt)

    dt = np.dtype([('ID1', np.int32),
                   ('ID2', np.int32),
                   ('FLOW', np.float64),
                   ('SATURATION', np.float64),
                   ])
    sat = np.array([(i, i, 0., 1.) for i in range(nlay * nrow * ncol)], dtype=dt)

    fname = os.path.join(ws, 'mybudget.bud')
    with open(fname, 'wb') as fbin:
        for kstp in range(1): #nstp[0]):
            write_budget(fbin, flowja, kstp=kstp + 1)
            write_budget(fbin, spdis, text='      DATA-SPDIS', imeth=6,
                         kstp=kstp + 1)
            write_budget(fbin, sat, text='        DATA-SAT', imeth=6,
                         kstp=kstp + 1)
            write_budget(fbin, wel, text='             WEL', imeth=6,
                         text2id2='           WEL-1', kstp=kstp + 1)
            write_budget(fbin, chd, text='             CHD', imeth=6,
                         text2id2='           CHD-1', kstp=kstp + 1)
    fbin.close()


    # flow model interface
    packagedata = [('GWFBUDGET', 'mybudget.bud', None),
                   ('GWFHEAD', 'myheads.hds', None)]
    fmi = flopy.mf6.ModflowGwtfmi(gwt, packagedata=packagedata)

    # output control
    oc = flopy.mf6.ModflowGwtoc(gwt,
                                budget_filerecord='{}.cbc'.format(gwtname),
                                concentration_filerecord='{}.ucn'.format(gwtname),
                                concentrationprintrecord=[
                                    ('COLUMNS', 10, 'WIDTH', 15,
                                     'DIGITS', 6, 'GENERAL')],
                                saverecord=[('CONCENTRATION', 'LAST'),
                                            ('BUDGET', 'LAST')],
                                printrecord=[('CONCENTRATION', 'LAST'),
                                             ('BUDGET', 'LAST')])

    obs_data = {'conc_obs.csv': [
                ('(1-1-10)', 'CONCENTRATION', (0, 0, 9)),
                ('(1-1-50)', 'CONCENTRATION', (0, 0, 49))],
                'flow_obs.csv': [
                ('c10-c11', 'FLOW-JA-FACE', (0, 0, 9), (0, 0, 10)),
                ('c50-c51', 'FLOW-JA-FACE', (0, 0, 49), (0, 0, 50)),
                ('c99-c100', 'FLOW-JA-FACE', (0, 0, 98), (0, 0, 99)),
                ]}

    obs_package = flopy.mf6.ModflowUtlobs(gwt, pname='conc_obs',
                                          filename='{}.obs'.format(gwtname),
                                          digits=10, print_input=True,
                                          continuous=obs_data)

    return sim
Пример #7
0
def build_model(idx, dir):
    nlay, nrow, ncol = 1, 1, 101
    perlen = [160.0, 1340.0]
    nper = len(perlen)
    tslength = 10.0
    nstp = [p / tslength for p in perlen]
    tsmult = nper * [1.0]
    delr = 0.16
    delc = 0.16
    top = 1.0
    botm = 0.0
    velocity = 0.1
    porosity = 0.37
    bulk_density = 1.587
    dispersivity = 1.0
    source_concentration = 0.05
    specific_discharge = velocity * porosity
    inflow_rate = specific_discharge * delc * (top - botm)

    nouter, ninner = 100, 300
    hclose, rclose, relax = 1e-6, 1e-6, 1.0

    tdis_rc = []
    for i in range(nper):
        tdis_rc.append((perlen[i], nstp[i], tsmult[i]))

    name = ex[idx]

    # build MODFLOW 6 files
    ws = dir
    sim = flopy.mf6.MFSimulation(sim_name=name,
                                 version="mf6",
                                 exe_name="mf6",
                                 sim_ws=ws)
    # create tdis package
    tdis = flopy.mf6.ModflowTdis(sim,
                                 time_units="SECONDS",
                                 nper=nper,
                                 perioddata=tdis_rc)

    # create gwt model
    gwtname = "gwt_" + name
    gwt = flopy.mf6.MFModel(
        sim,
        model_type="gwt6",
        modelname=gwtname,
        model_nam_file="{}.nam".format(gwtname),
    )
    gwt.name_file.save_flows = True

    # create iterative model solution and register the gwt model with it
    imsgwt = flopy.mf6.ModflowIms(
        sim,
        print_option="SUMMARY",
        outer_dvclose=hclose,
        outer_maximum=nouter,
        under_relaxation="NONE",
        inner_maximum=ninner,
        inner_dvclose=hclose,
        rcloserecord=rclose,
        linear_acceleration="BICGSTAB",
        scaling_method="NONE",
        reordering_method="NONE",
        relaxation_factor=relax,
        filename="{}.ims".format(gwtname),
    )
    sim.register_ims_package(imsgwt, [gwt.name])

    dis = flopy.mf6.ModflowGwtdis(
        gwt,
        nlay=nlay,
        nrow=nrow,
        ncol=ncol,
        delr=delr,
        delc=delc,
        top=top,
        botm=botm,
    )
    ic = flopy.mf6.ModflowGwtic(gwt, strt=0.0)
    adv = flopy.mf6.ModflowGwtadv(gwt, scheme="TVD")
    dsp = flopy.mf6.ModflowGwtdsp(gwt,
                                  xt3d_off=True,
                                  alh=dispersivity,
                                  ath1=dispersivity)
    mst = flopy.mf6.ModflowGwtmst(
        gwt,
        sorption=isotherm[idx],
        porosity=porosity,
        bulk_density=bulk_density,
        distcoef=distcoef[idx],
        sp2=sp2[idx],
    )

    # sources
    sourcerecarray = [("WEL-1", "AUX", "CONCENTRATION")]
    ssm = flopy.mf6.ModflowGwtssm(gwt, sources=sourcerecarray)

    # create a heads file with head equal top
    fname = os.path.join(ws, "myhead.hds")
    with open(fname, "wb") as fbin:
        kstp = 0
        totim = 0
        for kper in range(nper):
            totim += perlen[kper]
            write_head(
                fbin,
                top * np.ones((nrow, ncol)),
                kstp=kstp + 1,
                kper=kper + 1,
                pertim=perlen[kper],
                totim=totim,
            )

    # create a budget file
    qx = specific_discharge
    qy = 0.0
    qz = 0.0
    shape = (nlay, nrow, ncol)
    spdis, flowja = uniform_flow_field(qx, qy, qz, shape, delr=delr, delc=delc)
    dt = np.dtype([
        ("ID1", np.int32),
        ("ID2", np.int32),
        ("FLOW", np.float64),
        ("CONCENTRATION", np.float64),
    ])
    wel = [
        np.array([(0 + 1, 0 + 1, inflow_rate, source_concentration)],
                 dtype=dt),
        np.array([(0 + 1, 0 + 1, inflow_rate, 0.0)], dtype=dt),
    ]
    chd = np.array([(ncol - 1 + 1, ncol - 1 + 1, -inflow_rate, 0.0)], dtype=dt)

    dt = np.dtype([
        ("ID1", np.int32),
        ("ID2", np.int32),
        ("FLOW", np.float64),
        ("SATURATION", np.float64),
    ])
    sat = np.array([(i, i, 0.0, 1.0) for i in range(nlay * nrow * ncol)],
                   dtype=dt)

    fname = os.path.join(ws, "mybudget.bud")
    with open(fname, "wb") as fbin:
        kstp = 0
        totim = 0
        for kper in range(nper):
            totim += perlen[kper]
            delt = perlen[kper] / nstp[kper]
            write_budget(
                fbin,
                flowja,
                kstp=kstp + 1,
                kper=kper + 1,
                pertim=perlen[kper],
                totim=totim,
                delt=delt,
            )
            write_budget(
                fbin,
                spdis,
                text="      DATA-SPDIS",
                imeth=6,
                kstp=kstp + 1,
                kper=kper + 1,
                pertim=perlen[kper],
                totim=totim,
                delt=delt,
            )
            write_budget(
                fbin,
                sat,
                text="        DATA-SAT",
                imeth=6,
                kstp=kstp + 1,
                kper=kper + 1,
                pertim=perlen[kper],
                totim=totim,
                delt=delt,
            )
            write_budget(
                fbin,
                wel[kper],
                text="             WEL",
                imeth=6,
                text2id2="           WEL-1",
                kstp=kstp + 1,
                kper=kper + 1,
                pertim=perlen[kper],
                totim=totim,
                delt=delt,
            )
            write_budget(
                fbin,
                chd,
                text="             CHD",
                imeth=6,
                text2id2="           CHD-1",
                kstp=kstp + 1,
                kper=kper + 1,
                pertim=perlen[kper],
                totim=totim,
                delt=delt,
            )
    fbin.close()

    # flow model interface
    packagedata = [
        ("GWFBUDGET", "mybudget.bud", None),
        ("GWFHEAD", "myhead.hds", None),
    ]
    fmi = flopy.mf6.ModflowGwtfmi(gwt, packagedata=packagedata)

    # output control
    oc = flopy.mf6.ModflowGwtoc(
        gwt,
        budget_filerecord="{}.cbc".format(gwtname),
        concentration_filerecord="{}.ucn".format(gwtname),
        concentrationprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6,
                                   "GENERAL")],
        saverecord=[("CONCENTRATION", "LAST"), ("BUDGET", "LAST")],
        printrecord=[("CONCENTRATION", "LAST"), ("BUDGET", "LAST")],
    )

    obs_data = {
        "conc_obs.csv": [
            ("X008", "CONCENTRATION", (0, 0, 50)),
        ]
    }

    obs_package = flopy.mf6.ModflowUtlobs(
        gwt,
        pname="conc_obs",
        filename="{}.obs".format(gwtname),
        digits=10,
        print_input=True,
        continuous=obs_data,
    )

    return sim, None
Пример #8
0
def get_model(idx, dir):
    nlay, nrow, ncol = 1, 1, 3
    nper = 1
    perlen = [1.0]
    nstp = [1]
    tsmult = [1.]
    steady = [True]
    delr = 1.
    delc = 1.
    top = 1.
    laytyp = 0
    ss = 0.
    sy = 0.1
    botm = [0.]
    strt = 1.
    hnoflo = 1e30
    hdry = -1e30
    hk = 1.0

    nouter, ninner = 100, 300
    hclose, rclose, relax = 1e-6, 1e-6, 1.

    tdis_rc = []
    for i in range(nper):
        tdis_rc.append((perlen[i], nstp[i], tsmult[i]))

    name = ex[idx]

    # build MODFLOW 6 files
    ws = dir
    sim = flopy.mf6.MFSimulation(sim_name=name, version='mf6',
                                 exe_name='mf6',
                                 sim_ws=ws)
    # create tdis package
    tdis = flopy.mf6.ModflowTdis(sim, time_units='DAYS',
                                 nper=nper, perioddata=tdis_rc)

    # create gwt model
    gwtname = 'gwt_' + name
    gwt = flopy.mf6.MFModel(sim, model_type='gwt6', modelname=gwtname,
                            model_nam_file='{}.nam'.format(gwtname))
    gwt.name_file.save_flows = True

    # create iterative model solution and register the gwt model with it
    imsgwt = flopy.mf6.ModflowIms(sim, print_option='SUMMARY',
                                  outer_dvclose=hclose,
                                  outer_maximum=nouter,
                                  under_relaxation='NONE',
                                  inner_maximum=ninner,
                                  inner_dvclose=hclose, rcloserecord=rclose,
                                  linear_acceleration='BICGSTAB',
                                  scaling_method='NONE',
                                  reordering_method='NONE',
                                  relaxation_factor=relax,
                                  filename='{}.ims'.format(gwtname))
    sim.register_ims_package(imsgwt, [gwt.name])

    dis = flopy.mf6.ModflowGwtdis(gwt, nlay=nlay, nrow=nrow, ncol=ncol,
                                  delr=delr, delc=delc,
                                  top=top, botm=botm,
                                  idomain=1,
                                  filename='{}.dis'.format(gwtname))

    # initial conditions
    ic = flopy.mf6.ModflowGwtic(gwt, strt=10.,
                                filename='{}.ic'.format(gwtname))

    # advection
    adv = flopy.mf6.ModflowGwtadv(gwt)

    # mass storage and transfer
    mst = flopy.mf6.ModflowGwtmst(gwt, porosity=0.1)

    # output control
    oc = flopy.mf6.ModflowGwtoc(gwt,
                                budget_filerecord='{}.cbc'.format(gwtname),
                                concentration_filerecord='{}.ucn'.format(gwtname),
                                concentrationprintrecord=[
                                    ('COLUMNS', 10, 'WIDTH', 15,
                                     'DIGITS', 6, 'GENERAL')],
                                saverecord=[('CONCENTRATION', 'LAST'),
                                            ('BUDGET', 'LAST')],
                                printrecord=[('CONCENTRATION', 'LAST'),
                                             ('BUDGET', 'LAST')])

    # create a heads file with head equal top
    fname = os.path.join(ws, 'myhead.hds')
    with open(fname, 'wb') as fbin:
        for kstp in range(nstp[0]):
            write_head(fbin, top * np.ones((nrow, ncol)), kstp=kstp + 1)

    # create a budget file
    qx = 0.
    qy = 0.
    qz = 0.
    shape = (nlay, nrow, ncol)
    spdis, flowja = uniform_flow_field(qx, qy, qz, shape)
    dt = np.dtype([('ID1', np.int32),
                   ('ID2', np.int32),
                   ('FLOW', np.float64),
                   ('CONCENTRATION', np.float64),
                   ])
    print(flowja)
    flowja = np.array([ 0., 0.01,
                        0.,  0.,  -0.01,
                        0.,  0.01])

    dt = np.dtype([('ID1', np.int32),
                   ('ID2', np.int32),
                   ('FLOW', np.float64),
                   ('SATURATION', np.float64),
                   ])
    sat = np.array([(i, i, 0., 1.) for i in range(nlay * nrow * ncol)],
                   dtype=dt)


    fname = os.path.join(ws, 'mybudget.bud')
    with open(fname, 'wb') as fbin:
        for kstp in range(nstp[0]):
            write_budget(fbin, flowja, kstp=kstp + 1)
            write_budget(fbin, spdis, text='      DATA-SPDIS', imeth=6,
                         kstp=kstp + 1)
            write_budget(fbin, sat, text='        DATA-SAT', imeth=6,
                         kstp=kstp + 1)
    fbin.close()

    # flow model interface
    packagedata = [('GWFBUDGET', 'mybudget.bud', None),
                   ('GWFHEAD', 'myhead.hds', None)]
    fmi = flopy.mf6.ModflowGwtfmi(gwt, flow_imbalance_correction=True,
                                  packagedata=packagedata)

    return sim