Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
iu_cbc = 130
m = flopy.modflow.Modflow(nm, model_ws=ws,
exe_name=exe_name)
flopy.modflow.ModflowDis(m, nlay=nlay, nrow=nrow, ncol=ncol,
nper=nper, itmuni=4, lenuni=1,
perlen=perlen, nstp=nstp,
tsmult=tsmult, steady=True,
delr=delr, delc=delc,
top=top, botm=botm)
flopy.modflow.ModflowLpf(m, ipakcb=iu_cbc, laytyp=laytyp, hk=kh, vka=kv)
flopy.modflow.ModflowBas(m, ibound=1, strt=top)
# recharge
flopy.modflow.ModflowRch(m, ipakcb=iu_cbc, rech=rch, nrchop=1)
# wel
wd = [i for i in wel_loc] + [wel_q]
flopy.modflow.ModflowWel(m, ipakcb=iu_cbc, stress_period_data={0: wd})
# river
rd = []
for i in range(nrow):
rd.append([0, i, ncol - 1, riv_h, riv_c, riv_z])
flopy.modflow.ModflowRiv(m, ipakcb=iu_cbc, stress_period_data={0: rd})
# output control
flopy.modflow.ModflowOc(m, stress_period_data={(0, 0): ['save head',
'save budget',
'print head']})
flopy.modflow.ModflowPcg(m, hclose=1e-6, rclose=1e-3, iter1=100, mxiter=50)
m.write_input()
if run:
success, buff = m.run_model()
assert success, 'mf2005 model did not run'
m = fm.Modflow(cls.modelname, model_ws=cls.model_ws, external_path=external_path)
dis = fm.ModflowDis(m, nper=nper, nlay=nlay, nrow=size, ncol=size,
top=nlay, botm=list(range(nlay)))
rch = fm.ModflowRch(m, rech={k: .001 - np.cos(k) * .001 for k in range(nper)})
ra = fm.ModflowWel.get_empty(size ** 2)
well_spd = {}
for kper in range(nper):
ra_per = ra.copy()
ra_per['k'] = 1
ra_per['i'] = (np.ones((size, size)) * np.arange(size)).transpose().ravel().astype(int)
ra_per['j'] = list(range(size)) * size
well_spd[kper] = ra
wel = fm.ModflowWel(m, stress_period_data=well_spd)
# SFR package
rd = fm.ModflowSfr2.get_empty_reach_data(nsfr)
rd['iseg'] = range(len(rd))
rd['ireach'] = 1
sd = fm.ModflowSfr2.get_empty_segment_data(nsfr)
sd['nseg'] = range(len(sd))
sfr = fm.ModflowSfr2(reach_data=rd, segment_data=sd, model=m)
cls.init_time = time.time() - t0
cls.m = m
def test_none_spdtype():
# ensure that -1 and None work as valid list entries in the
# stress period dictionary
model_ws = os.path.join('.', 'temp', 't068c')
mf = flopy.modflow.Modflow(model_ws=model_ws, exe_name=mf_exe_name)
dis = flopy.modflow.ModflowDis(mf, nper=2)
bas = flopy.modflow.ModflowBas(mf)
lpf = flopy.modflow.ModflowLpf(mf)
spd = {0: -1, 1: None}
wel = flopy.modflow.ModflowWel(mf, stress_period_data=spd)
pcg = flopy.modflow.ModflowPcg(mf)
mf.write_input()
mf2 = flopy.modflow.Modflow.load('modflowtest.nam', model_ws=model_ws,
verbose=True)
if run:
success, buff = mf.run_model(report=True)
assert success
# test get_dataframe() on mflist obj
sp_data3 = {0: [1, 1, 1, 1.0],
1: [[1, 1, 3, 3.0], [1, 1, 2, 6.0]],
2: [[1, 2, 4, 8.0], [1, 2, 3, 4.0], [1, 2, 2, 4.0],
[1, 1, 3, 3.0], [1, 1, 2, 6.0]]}
wel4 = flopy.modflow.ModflowWel(ml, stress_period_data=sp_data3)
df = wel4.stress_period_data.get_dataframe()
assert df['flux0'].sum() == 1.
assert df['flux1'].sum() == 9.
assert df['flux2'].sum() == 25.
sp_data4 = {0: [1, 1, 1, 1.0],
1: [[1, 1, 3, 3.0], [1, 1, 3, 6.0]],
2: [[1, 2, 4, 8.0], [1, 2, 4, 4.0], [1, 2, 4, 4.0],
[1, 1, 3, 3.0], [1, 1, 3, 6.0]]}
wel5 = flopy.modflow.ModflowWel(ml, stress_period_data=sp_data4)
df = wel5.stress_period_data.get_dataframe()
assert df['flux0'].sum() == 1.
assert df['flux1'].sum() == 9.
assert df.loc[
df.apply(lambda x: x.k == 1 and x.i == 1 and x.j == 3, axis=1),
'flux2'].values == 9.0
assert df.loc[
df.apply(lambda x: x.k == 1 and x.i == 2 and x.j == 4, axis=1),
'flux2'].values == 16.0
# We do not need to add a dictionary entry for stress period 3.
# Flopy will automatically take the list from stress period 2 and apply it
# to the end of the simulation
stress_period_data = {0: bound_sp1, 1: bound_sp2}
# Create the flopy ghb object
ghb = flopy.modflow.ModflowGhb(mf, stress_period_data=stress_period_data)
# Create the well package
# Remember to use zero-based layer, row, column indices!
pumping_rate = -500.
wel_sp1 = [[0, nrow/2 - 1, ncol/2 - 1, 0.]]
wel_sp2 = [[0, nrow/2 - 1, ncol/2 - 1, 0.]]
wel_sp3 = [[0, nrow/2 - 1, ncol/2 - 1, pumping_rate]]
stress_period_data = {0: wel_sp1, 1: wel_sp2, 2: wel_sp3}
wel = flopy.modflow.ModflowWel(mf, stress_period_data=stress_period_data)
# Output control
stress_period_data = {}
for kper in range(nper):
for kstp in range(nstp[kper]):
stress_period_data[(kper, kstp)] = ['save head',
'save drawdown',
'save budget',
'print head',
'print budget']
oc = flopy.modflow.ModflowOc(mf, stress_period_data=stress_period_data,
compact=True)
# Write the model input files
mf.write_input()
iswiobs = 1051
modelname = 'swiex4_s1'
if not skipRuns:
ml = flopy.modflow.Modflow(modelname, version='mf2005', exe_name=exe_name,
model_ws=workspace)
discret = flopy.modflow.ModflowDis(ml, nlay=nlay, nrow=nrow, ncol=ncol,
laycbd=0,
delr=delr, delc=delc, top=botm[0],
botm=botm[1:],
nper=nper, perlen=perlen, nstp=nstp,
steady=steady)
bas = flopy.modflow.ModflowBas(ml, ibound=ibound, strt=ihead)
lpf = flopy.modflow.ModflowLpf(ml, laytyp=laytyp, hk=hk, vka=vka)
wel = flopy.modflow.ModflowWel(ml, stress_period_data=base_well_data)
ghb = flopy.modflow.ModflowGhb(ml, stress_period_data=ghb_data)
rch = flopy.modflow.ModflowRch(ml, rech=rch_data)
swi = flopy.modflow.ModflowSwi2(ml, iswizt=55, nsrf=1, istrat=1,
toeslope=toeslope,
tipslope=tipslope, nu=nu,
zeta=z, ssz=ssz, isource=iso, nsolver=1,
nadptmx=nadptmx, nadptmn=nadptmn,
nobs=nobs, iswiobs=iswiobs, obsnam=obsnam,
obslrc=obslrc)
oc = flopy.modflow.ModflowOc(ml, stress_period_data=ocspd)
pcg = flopy.modflow.ModflowPcg(ml, hclose=1.0e-6, rclose=3.0e-3,
mxiter=100, iter1=50)
# create model files
ml.write_input()
# run the model
m = ml.run_model(silent=False)
arr[np.where(arr == 0.0)] = np.NaN
m4d[iper + 1] = arr
iper += 1
# model wasn't passed, then create a generic model
if model is None:
model = Modflow("test")
# if model doesn't have a wel package, then make a generic one...
# need this for the from_m4d method
if model.wel is None:
ModflowWel(model)
# get the stress_period_data dict {kper:np recarray}
sp_data = MfList.from_4d(model, "WEL", {"flux": m4d})
wel = ModflowWel(model, stress_period_data=sp_data)
return wel
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,
mxiter=100, iter1=50)
# --write the modflow files
ml.write_input()
m = ml.run_model(silent=False)
# --read model zeta
get_stp = [364, 729, 1094, 1459, 364, 729, 1094, 1459]
get_per = [0, 0, 0, 0, 1, 1, 1, 1]
nswi_times = len(get_per)
arr = cbf.get_data(kstpkper=kstpkper, text=text, full3D=True)
if len(arr) > 0:
arr = arr[0]
print(arr.max(), arr.min(), arr.sum())
# masked where zero
arr[np.where(arr == 0.0)] = np.NaN
m4d[iper + 1] = arr
iper += 1
# model wasn't passed, then create a generic model
if model is None:
model = Modflow("test")
# if model doesn't have a wel package, then make a generic one...
# need this for the from_m4d method
if model.wel is None:
ModflowWel(model)
# get the stress_period_data dict {kper:np recarray}
sp_data = MfList.from_4d(model, "WEL", {"flux": m4d})
wel = ModflowWel(model, stress_period_data=sp_data)
return wel