gpt4 book ai didi

python - 为什么 Flopy 给出相同的结果?

转载 作者:行者123 更新时间:2023-12-01 09:29:11 26 4
gpt4 key购买 nike

我尝试使用 flopy ,所以我可以尝试使用 python 和 modflow 运行一些优化程序。 Modflow 需要使用大量数据,我们使用不同的文件提供这些信息。

我们提供输入和软盘运行modflow

我的问题是,无论我给出什么输入,软盘似乎都会忽略输入文件并给出相同的结果。

代码如下:

nper = 10
class BASreader:
def __init__(self):
self.ibound = None
self.head = None

with open("inps/bas/ibound", "r") as f:
data = f.read().replace("-", " -").split()
data = [int(x) for x in data]
data = np.array(data).reshape(1, 71, 24)
self.ibound = data

with open("inps/bas/head", "r") as f:
data = f.read().split()
data = [float(x) for x in data]
self.head = np.array(data).reshape(1, 71, 24)


class Modflow:
def __init__(self):
self.modelname = 'outs/gen1'
self.mf = flopy.modflow.Modflow(self.modelname, exe_name=r'G:\Program Files (x86)\Visual MODFLOW\mf2005.exe')

dis = flopy.modflow.ModflowDis.load("inps/yo.dis", self.mf)

basreader = BASreader()
bas = flopy.modflow.ModflowBas(self.mf, ibound=basreader.ibound, strt=basreader.head)
self.prev_headdata = basreader.head

wel = flopy.modflow.ModflowWel(self.mf, stress_period_data=WellProvider(nper).wells)

fname = 'inps/yo.evt'
fhandle = open(fname, 'r')
packages = []
ext_unit_dict = {22: flopy.utils.mfreadnam.NamData('EVT', fname, fhandle, packages)}
evt = flopy.modflow.ModflowEvt.load(fhandle, self.mf, ext_unit_dict=ext_unit_dict)
fhandle.close()

rech = {}
for x in range(nper):
rech[x] = 1.44e-5
rch = flopy.modflow.ModflowRch(self.mf, rech=rech)

stress_period_data = {}
for kper in range(nper):
for kstp in range(int(nper/10)):
stress_period_data[(kper, kstp)] = ['save head',
'save drawdown',
'save budget',
'print head',
'print drawdown',
'print budget']
oc = flopy.modflow.ModflowOc(self.mf, stress_period_data=stress_period_data, compact=True)
chd = flopy.modflow.ModflowChd.load("inps/yo.chd", self.mf)
lpf = flopy.modflow.ModflowLpf(self.mf, hk=14.44, vka=14.44, ipakcb=53, sy=0.22)

self.mf.write_input()

def run(self):
success, buff = self.mf.run_model(silent=True)
headobj = bf.HeadFile(self.modelname + '.hds')
newheaddata = headobj.get_alldata()[-1][0]
return newheaddata

mdflw = Modflow()
mdflw.run()

现在,即使我更改 EVT、RCH 或 WEL 信息,结果也是相同的。我什至尝试不包含上述文件,但结果仍然相同。有什么指点吗?

最佳答案

脚本的此修订会导致不同的水头结果(因为使用了不同的地下水补给值)。我在修改后的示例中使用了 bcf2ss MODFLOW-2005 输入文件作为基础文件。

不完全确定为什么您的脚本无法运行,因为您的输入文件不可用。

import os
import numpy as np
import flopy


class BASreader:
def __init__(self):
self.ibound = None
self.head = None

with open("inps/bas/ibound", "r") as f:
data = f.read().replace("-", " -").split()
data = [int(x) for x in data]
data = np.array(data).reshape(2, 10, 15)
self.ibound = data

with open("inps/bas/head", "r") as f:
data = f.read().split()
data = [float(x) for x in data]
self.head = np.array(data).reshape(2, 10, 15)


class Modflow:
def __init__(self, ws='outs', rech_val=.0040, wel_data=None):
self.model_ws = ws
self.modelname = 'gen1'
self.mf = flopy.modflow.Modflow(self.modelname, exe_name='mf2005',
model_ws=self.model_ws)

dis = flopy.modflow.ModflowDis.load("inps/yo.dis", self.mf, check=False)
nper = dis.nper
nstp = dis.nstp.array

basreader = BASreader()
bas = flopy.modflow.ModflowBas(self.mf, ibound=basreader.ibound,
strt=basreader.head)
self.prev_headdata = basreader.head
bcf = flopy.modflow.ModflowBcf.load("inps/yo.bc6", self.mf)

if wel_data is None:
wel_data = [[1, 2, 3, -35000.],
[1, 7, 3, -35000.]]
wel_spd = {1: wel_data}

wel = flopy.modflow.ModflowWel(self.mf,
stress_period_data=wel_spd)

riv = flopy.modflow.ModflowRiv.load('inps/yo.riv', self.mf, check=False)

rech = {}
for x in range(nper):
rech[x] = rech_val
rch = flopy.modflow.ModflowRch(self.mf, rech=rech)

pcg = flopy.modflow.ModflowPcg.load('inps/yo.pcg', self.mf)

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 drawdown',
'print budget']
oc = flopy.modflow.ModflowOc(self.mf,
stress_period_data=stress_period_data,
compact=True)

self.mf.write_input()

def run(self):
success, buff = self.mf.run_model(silent=True)
fpth = os.path.join(self.model_ws, self.modelname + '.hds')
headobj = flopy.utils.HeadFile(fpth)
newheaddata = headobj.get_data(idx=1)
return newheaddata


if __name__ == "__main__":
m1 = Modflow()
h1 = m1.run()

m2 = Modflow(rech_val=.0041)
h2 = m2.run()

assert np.array_equal(h1, h2), 'h1 does not equal h2'

关于python - 为什么 Flopy 给出相同的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50111034/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com