Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_how():
import numpy as np
import flopy
ml = flopy.modflow.Modflow(model_ws=out_dir)
ml.array_free_format = False
dis = flopy.modflow.ModflowDis(ml, nlay=2, nrow=10, ncol=10)
arr = np.ones((ml.nrow, ml.ncol))
u2d = flopy.utils.Util2d(ml, arr.shape, np.float32, arr, "test", locat=1)
print(u2d.get_file_entry())
u2d.how = "constant"
print(u2d.get_file_entry())
u2d.fmtin = "(binary)"
print(u2d.get_file_entry())
def test_transient2d():
ml = flopy.modflow.Modflow()
dis = flopy.modflow.ModflowDis(ml, nlay=10, nrow=10, ncol=10, nper=3)
t2d = Transient2d(ml, (10, 10), np.float32, 10., "fake")
a1 = t2d.array
assert a1.shape == (3, 1, 10, 10), a1.shape
t2d.cnstnt = 2.0
assert np.array_equal(t2d.array, np.zeros((3, 1, 10, 10)) + 20.0)
t2d[0] = 1.0
t2d[2] = 999
assert np.array_equal(t2d[0].array, np.ones((ml.nrow, ml.ncol)))
assert np.array_equal(t2d[2].array, np.ones((ml.nrow, ml.ncol)) * 999)
m4d = t2d.array
t2d2 = Transient2d.from_4d(ml, "rch", {"rech": m4d})
m4d2 = t2d2.array
assert np.array_equal(m4d, m4d2)
# 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)
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)
rf0shp = os.path.join(gridgen_ws, 'rf0')
xmin = 7 * delr
xmax = 12 * delr
def stress_util2d(ml, nlay, nrow, ncol):
dis = flopy.modflow.ModflowDis(ml, nlay=nlay, nrow=nrow, ncol=ncol)
hk = np.ones((nlay, nrow, ncol))
vk = np.ones((nlay, nrow, ncol)) + 1.0
# save hk up one dir from model_ws
fnames = []
for i, h in enumerate(hk):
fname = os.path.join(out_dir, "test_{0}.ref".format(i))
fnames.append(fname)
np.savetxt(fname, h, fmt="%15.6e", delimiter='')
vk[i] = i + 1.
lpf = flopy.modflow.ModflowLpf(ml, hk=fnames, vka=vk)
# util2d binary check
ml.lpf.vka[0].format.binary = True
# util3d cnstnt propagation test
ml.lpf.vka.cnstnt = 2.0
icnt = 0
else:
ocspd[(i, j)] = []
solver2params = {'mxiter': 100, 'iter1': 20, 'npcond': 1, 'zclose': 1.0e-6,
'rclose': 3e-3, 'relax': 1.0,
'nbpol': 2, 'damp': 1.0, 'dampt': 1.0}
# --create model file and run model
modelname = 'swi2ex5'
mf_name = 'mf2005'
if not skipRuns:
ml = flopy.modflow.Modflow(modelname, version='mf2005',
exe_name=mf_name,
model_ws=dirs[0])
discret = flopy.modflow.ModflowDis(ml, nrow=nrow, ncol=ncol, nlay=nlay,
delr=delr, delc=delc, top=0,
botm=bot,
laycbd=0, nper=nper, perlen=perlen,
nstp=nstp, steady=steady)
bas = flopy.modflow.ModflowBas(ml, ibound=ibound, strt=ihead)
lpf = flopy.modflow.ModflowLpf(ml, hk=kh, vka=kv, ss=ss, sy=ssz,
vkcb=0,
laytyp=0, layavg=1)
wel = flopy.modflow.ModflowWel(ml, stress_period_data=well_data)
swi = flopy.modflow.ModflowSwi2(ml, iswizt=55, npln=1, istrat=1,
toeslope=0.025, tipslope=0.025,
nu=[0, 0.025], zeta=z, ssz=ssz,
isource=isource, nsolver=2,
solver2params=solver2params)
oc = flopy.modflow.ModflowOc(ml, stress_period_data=ocspd)
pcg = flopy.modflow.ModflowPcg(ml, hclose=1.0e-6, rclose=3.0e-3,
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')
ncol = 100
delr = Lx / ncol
delc = 1.0
delv = Lz / nlay
henry_top = 1.
henry_botm = np.linspace(henry_top - delv, 0., nlay)
qinflow = 5.702 # m3/day
dmcoef = 0.57024 # m2/day Could also try 1.62925 as another case of the Henry problem
hk = 864. # m/day
# Create the basic MODFLOW model data
modelname = 'henry'
m = flopy.seawat.Seawat(modelname, exe_name="swtv4", model_ws=workspace)
# Add DIS package to the MODFLOW model
dis = flopy.modflow.ModflowDis(m, nlay, nrow, ncol, nper=1, delr=delr,
delc=delc, laycbd=0, top=henry_top,
botm=henry_botm, perlen=1.5, nstp=15)
# Variables for the BAS package
ibound = np.ones((nlay, nrow, ncol), dtype=np.int32)
ibound[:, :, -1] = -1
bas = flopy.modflow.ModflowBas(m, ibound, 0)
# Add LPF package to the MODFLOW model
lpf = flopy.modflow.ModflowLpf(m, hk=hk, vka=hk, ipakcb=53)
# Add PCG Package to the MODFLOW model
pcg = flopy.modflow.ModflowPcg(m, hclose=1.e-8)
# Add OC package to the MODFLOW model
oc = flopy.modflow.ModflowOc(m,
# create isource for SWI2
isource = np.ones((nrow, ncol), np.int)
isource[0, 0] = 2
ocdict = {}
for idx in range(49, 200, 50):
key = (0, idx)
ocdict[key] = ['save head', 'save budget']
key = (0, idx + 1)
ocdict[key] = []
# create flopy modflow object
ml = flopy.modflow.Modflow(modelname, version='mf2005', exe_name=exe_name,
model_ws=workspace)
# create flopy modflow package objects
discret = flopy.modflow.ModflowDis(ml, nlay=nlay, nrow=nrow, ncol=ncol,
delr=delr, delc=delc,
top=0, botm=[-40.0],
perlen=400, nstp=200)
bas = flopy.modflow.ModflowBas(ml, ibound=ibound, strt=0.0)
lpf = flopy.modflow.ModflowLpf(ml, hk=2., vka=2.0, vkcb=0, laytyp=0,
layavg=0)
wel = flopy.modflow.ModflowWel(ml, stress_period_data={0: [(0, 0, 0, 1)]})
swi = flopy.modflow.ModflowSwi2(ml, iswizt=55, npln=1, istrat=1,
toeslope=0.2, tipslope=0.2, nu=[0, 0.025],
zeta=z, ssz=0.2, isource=isource,
nsolver=1)
oc = flopy.modflow.ModflowOc(ml, stress_period_data=ocdict)
pcg = flopy.modflow.ModflowPcg(ml)
# create model files
ml.write_input()
# run the model
z0[0, 0, 38:] = -40
z1[0, 0, 22:30] = np.arange(-2.5, -40, -5)
z1[0, 0, 30:] = -40
z = []
z.append(z0)
z.append(z1)
ssz = 0.2
isource = np.ones((nrow, ncol), 'int')
isource[0, 0] = 2
# stratified model
modelname = 'swiex2_strat'
print('creating...', modelname)
ml = flopy.modflow.Modflow(modelname, version='mf2005', exe_name=mf_name,
model_ws=dirs[0])
discret = flopy.modflow.ModflowDis(ml, nlay=1, ncol=ncol, nrow=nrow,
delr=delr,
delc=1,
top=0, botm=[-40.0],
nper=nper, perlen=perlen, nstp=nstp)
bas = flopy.modflow.ModflowBas(ml, ibound=ibound, strt=0.05)
bcf = flopy.modflow.ModflowBcf(ml, laycon=0, tran=2 * 40)
swi = flopy.modflow.ModflowSwi2(ml, iswizt=55, nsrf=nsurf, istrat=1,
toeslope=0.2, tipslope=0.2,
nu=[0, 0.0125, 0.025],
zeta=z, ssz=ssz, isource=isource,
nsolver=1)
oc = flopy.modflow.ModflowOc(ml,
stress_period_data={(0, 999): ['save head']})
pcg = flopy.modflow.ModflowPcg(ml)
ml.write_input()
# run stratified model