In [1]:
# I installed flopy thusly:
# svn checkout http://flopy.googlecode.com/svn/trunk/ flopy
# pip install ./flopy
#
# but you could also use:
#import sys
#sys.path.append('/Users/mark/flopy/svn/trunk/')
import flopy.modflow as fmf
import flopy.utils as fut
%pylab inline
In [2]:
cd /usgs/data2/notebook/lake_example
We are creating a square model with a specified head equal to h1
along all boundaries. The head at the cell in the center in the top layer is fixed to h2
. First, set the name of the model and the parameters of the model: the number of layers Nlay
, the number of rows and columns N
, lengths of the sides of the model L
, aquifer thickness H
, hydraulic conductivity k
In [3]:
name = 'lake_example'
h1 = 100
h2 = 90
Nlay = 10
N = 101
L = 400.0
H = 50.0
k = 1.0
Create a MODFLOW model and store it (in this case in the variable ml
, but you can call it whatever you want). The modelname will be the name given to all MODFLOW files (input and output). The exe_name should be the full path to your MODFLOW executable. The version is either 'mf2k' for MODFLOW2000 or 'mf2005'for MODFLOW2005.
In [4]:
ml = fmf.Modflow(modelname=name, exe_name='/usgs/data2/rsignell/modflow/Unix/src/mf2005', version='mf2005')
Define the discretization of the model. All layers are given equal thickness. The bot
array is build from the Hlay
values to indicate top and bottom of each layer, and delrow
and delcol
are computed from model size L
and number of cells N
. Once these are all computed, the Discretization file is built.
In [5]:
bot = linspace(-H/Nlay,-H,Nlay)
delrow = delcol = L/(N-1)
dis = fmf.ModflowDis(ml,nlay=Nlay,nrow=N,ncol=N,delr=delrow,delc=delcol,top=0.0,botm=bot,laycbd=0)
Next we specify the boundary conditions and starting heads with the Basic package. The ibound
array will be 1
in all cells in all layers, except for along the boundary and in the cell at the center in the top layer where it is set to -1
to indicate fixed heads. The starting heads are used to define the heads in the fixed head cells (this is a steady simulation, so none of the other starting values matter). So we set the starting heads to h1
everywhere, except for the head at the center of the model in the top layer.
In [6]:
Nhalf = (N-1)/2
ibound = ones((Nlay,N,N))
ibound[:,0,:] = -1; ibound[:,-1,:] = -1; ibound[:,:,0] = -1; ibound[:,:,-1] = -1
ibound[0,Nhalf,Nhalf] = -1
start = h1 * ones((N,N))
start[Nhalf,Nhalf] = h2
bas = fmf.ModflowBas(ml,ibound=ibound,strt=start)
The aquifer properties (really only the hydraulic conductivity) are defined with the LPF package.
In [7]:
lpf = fmf.ModflowLpf(ml, hk=k)
Finally, we need to specify the solver we want to use (PCG with default values), and the output control (using the default values). Then we are ready to write all MODFLOW input files and run MODFLOW.
In [8]:
pcg = fmf.ModflowPcg(ml)
oc = fmf.ModflowOc(ml)
ml.write_input()
ml.run_model3()
Once the model has terminated normally, we can read the heads file. First, a link to the heads file is created with HeadFile
. The link can then be accessed with the get_data
function, by specifying, in this case, the step number and period number for which we want to retrieve data. A three-dimensional array is returned of size nlay, nrow, ncol
. Matplotlib contouring functions are used to make contours of the layers or a cross-section.
In [9]:
hds = fut.HeadFile(name+'.hds')
h = hds.get_data(kstp=1, kper=1)
x = y = linspace(0,L,N)
c = contour(x,y,h[0],arange(90,100.1,0.2))
clabel(c,fmt='%1.1f')
axis('scaled')
Out[9]:
In [10]:
x = y = linspace(0,L,N)
c = contour(x,y,h[-1],arange(90,100.1,0.2))
clabel(c,fmt='%1.1f')
axis('scaled')
Out[10]:
In [11]:
z = linspace(-H/Nlay/2,-H+H/Nlay/2,Nlay)
c = contour(x,z,h[:,50,:],arange(90,100.1,.2))
axis('scaled')
Out[11]:
In [11]: