In [1]:
import os
import numpy as np
import flopy
starting_dir = os.getcwd()
base_dir = "base_model_dir"
if not os.path.exists(base_dir):
os.mkdir(base_dir)
# change to base_dir
os.chdir(base_dir)
nlay, nrow, ncol = 1, 1, 10
ml = flopy.modflow.Modflow(modelname="base",external_path="ref")
dis = flopy.modflow.ModflowDis(ml, nrow=1, ncol=10,
nlay=nlay, nper=2, perlen=[1,1],
steady=[True,True])
bas = flopy.modflow.ModflowBas(ml, ibound=1)
hk = np.zeros((nlay, nrow, ncol))+2.5
lpf = flopy.modflow.ModflowLpf(ml, hk=hk,vka=hk)
well_data = {}
well_data[0] = [0, 0, 9, 0.5]
well_data[1] = [0, 0, 9, 1.0]
wel = flopy.modflow.ModflowWel(ml, stress_period_data=well_data)
ghb_data = {}
ghb_data[0] = [0, 0, 0, 0.5, 1000.0]
ghb = flopy.modflow.ModflowGhb(ml, stress_period_data=ghb_data)
ml.write_input()
# change back
os.chdir(starting_dir)
Now load the model using base_dir
as the model_ws
arg
In [2]:
ml_loaded = flopy.modflow.Modflow.load("base.nam",model_ws=base_dir)
print ml_loaded.get_package("lpf").hk.array
ml_loaded.change_model_ws("new_dir")
ml_loaded.write_input()
Now without free_format
which results in old-style control records and unit numbers in the nam
file
In [3]:
base_dir = "base_model_dir"
if not os.path.exists(base_dir):
os.mkdir(base_dir)
# change to base_dir
os.chdir(base_dir)
nlay, nrow, ncol = 1, 1, 10
ml = flopy.modflow.Modflow(modelname="base",external_path="ref")
ml.array_free_format = False
dis = flopy.modflow.ModflowDis(ml, nrow=1, ncol=10,
nlay=nlay, nper=2, perlen=[1,1],
steady=[True,True])
bas = flopy.modflow.ModflowBas(ml, ibound=1)
hk = np.zeros((nlay, nrow, ncol))+2.5
lpf = flopy.modflow.ModflowLpf(ml, hk=hk,vka=hk)
well_data = {}
well_data[0] = [0, 0, 9, 0.5]
well_data[1] = [0, 0, 9, 1.0]
wel = flopy.modflow.ModflowWel(ml, stress_period_data=well_data)
ghb_data = {}
ghb_data[0] = [0, 0, 0, 0.5, 1000.0]
ghb = flopy.modflow.ModflowGhb(ml, stress_period_data=ghb_data)
ml.write_input()
# change back
os.chdir("..")
In [4]:
ml_loaded = flopy.modflow.Modflow.load("base.nam",model_ws=base_dir)
print ml_loaded.get_package("lpf").hk.array
ml_loaded.change_model_ws("new_dir2")
ml_loaded.write_input()
In [ ]: