Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
300 changes: 300 additions & 0 deletions examples/lake_example/.ipynb_checkpoints/lake_example-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"FloPy is using the following executable to run the model: C:\\WRDAPP\\mf2005.1_12\\bin\\mf2005.EXE\n",
"\n",
" MODFLOW-2005 \n",
" U.S. GEOLOGICAL SURVEY MODULAR FINITE-DIFFERENCE GROUND-WATER FLOW MODEL\n",
" Version 1.12.00 2/3/2017 \n",
"\n",
" Using NAME file: lake_example.nam \n",
" Run start date and time (yyyy/mm/dd hh:mm:ss): 2019/01/22 0:04:51\n",
"\n",
" Solving: Stress period: 1 Time step: 1 Ground-Water Flow Eqn.\n",
" Run end date and time (yyyy/mm/dd hh:mm:ss): 2019/01/22 0:04:53\n",
" Elapsed run time: 1.957 Seconds\n",
"\n",
" Normal termination of simulation\n"
]
}
],
"source": [
"import os\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"\n",
"import flopy.modflow as mf\n",
"import flopy.utils as fu\n",
"import pprint\n",
"import shutil\n",
"\n",
"workspace = os.path.join('ascii')\n",
"output = os.path.join('output')\n",
"\n",
"# delete directories if existing\n",
"if os.path.exists(workspace):\n",
" shutil.rmtree(workspace)\n",
"\n",
"if os.path.exists(output):\n",
" shutil.rmtree(output)\n",
"\n",
"if not os.path.exists(workspace):\n",
" os.makedirs(workspace)\n",
"\n",
"if not os.path.exists(output):\n",
" os.makedirs(output)\n",
"\n",
"name = 'lake_example'\n",
"\n",
"# --- Setting up the parameters\n",
"# Groundwater heads\n",
"h1 = 100 #in the boundaries\n",
"h2 = 90 # water-level-lake\n",
"\n",
"# Number of layers\n",
"Nlay = 10\n",
"\n",
"# Number of columns and rows\n",
"# we are assuming that NCol = NRow\n",
"N = 101 \n",
"\n",
"# The length and with of the model\n",
"L = 400.0 \n",
"\n",
"# The height of the model\n",
"H = 50.0 \n",
"k = 1.0\n",
"\n",
"# Intstantiating the Modflow-Object, ml is here an invented name\n",
"ml = mf.Modflow(modelname=name, exe_name='mf2005', version='mf2005', model_ws=workspace)\n",
"\n",
"# Calculation of the bottom-height of each layer\n",
"# more information: http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.linspace.html\n",
"bot = np.linspace(-H/Nlay,-H,Nlay) \n",
"# result is: \n",
"# array([ -5., -10., -15., -20., -25., -30., -35., -40., -45., -50.])\n",
"\n",
"\n",
"# calculation of row-width and col-width\n",
"delrow = delcol = L/(N-1) \n",
"# result is: \n",
"# 4\n",
"\n",
"# instantiante the discretization object\n",
"dis = mf.ModflowDis(ml, nlay=Nlay, nrow=N, ncol=N, delr=delrow, delc=delcol, top=0.0, botm=bot, laycbd=0)\n",
"\n",
"# helping-variable\n",
"Nhalf = (N-1)/2 \n",
"\n",
"# iBound-Configuration\n",
"# http://water.usgs.gov/nrp/gwsoftware/modflow2000/MFDOC/index.html?bas6.htm\n",
"# If IBOUND(J,I,K) < 0, cell J,I,K has a constant head.\n",
"# If IBOUND(J,I,K) = 0, cell J,I,K is inactive.\n",
"# If IBOUND(J,I,K) > 0, cell J,I,K is active.\n",
"#\n",
"# every cell in the model has to be defined\n",
"# create an 3-dimensional ibound-array with all cells=1\n",
"ibound = np.ones((Nlay,N,N)) \n",
"# result is:\n",
"# array([[[ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# ..., \n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.]],\n",
"# \n",
"# [[ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# ..., \n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.]],\n",
"# \n",
"# [[ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# ..., \n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.]],\n",
"# \n",
"# ..., \n",
"# [[ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# ..., \n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.]],\n",
"# \n",
"# [[ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# ..., \n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.]],\n",
"# \n",
"# [[ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# ..., \n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.],\n",
"# [ 1., 1., 1., ..., 1., 1., 1.]]])\n",
"\n",
"\n",
"# Set all elements in the first row to -1\n",
"ibound[:,0,:] = -1 \n",
"\n",
"# Set all elements in the last row to -1\n",
"ibound[:,-1,:] = -1\n",
"\n",
"# Set every first element of every column to -1\n",
"ibound[:,:,0] = -1\n",
"\n",
"# Set every last element of every column to -1\n",
"ibound[:,:,-1] = -1\n",
"\n",
"#result is:\n",
"#array([[[-1., -1., -1., ..., -1., -1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# ..., \n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., -1., -1., ..., -1., -1., -1.]],\n",
"#\n",
"# [[-1., -1., -1., ..., -1., -1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# ..., \n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., -1., -1., ..., -1., -1., -1.]],\n",
"#\n",
"# [[-1., -1., -1., ..., -1., -1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# ..., \n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., -1., -1., ..., -1., -1., -1.]],\n",
"#\n",
"# ..., \n",
"# [[-1., -1., -1., ..., -1., -1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# ..., \n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., -1., -1., ..., -1., -1., -1.]],\n",
"#\n",
"# [[-1., -1., -1., ..., -1., -1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# ..., \n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., -1., -1., ..., -1., -1., -1.]],\n",
"#\n",
"# [[-1., -1., -1., ..., -1., -1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# ..., \n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., 1., 1., ..., 1., 1., -1.],\n",
"# [-1., -1., -1., ..., -1., -1., -1.]]])\n",
"\n",
"# set center cell in upper layer to constant head (-1)\n",
"Nhalf=int(Nhalf)\n",
"ibound[0,Nhalf,Nhalf] = -1 \n",
"\n",
"# defining the start-values\n",
"# in the calculation only the -1 cells will be considered\n",
"#\n",
"# all values are set to h1\n",
"start = h1 * np.ones((N,N))\n",
"# and the center value is set to h2\n",
"start[Nhalf,Nhalf] = h2\n",
"\n",
"# instantiate the modflow-basic package with iBound and startvalues\n",
"bas = mf.ModflowBas(ml,ibound=ibound,strt=start)\n",
"\n",
"# set the aquifer properties with the lpf-package\n",
"lpf = mf.ModflowLpf(ml, hk=k)\n",
" \n",
"# instantiation of the solver with default values\n",
"pcg = mf.ModflowPcg(ml)\n",
"\n",
"# instantiation of the output control with default values\n",
"oc = mf.ModflowOc(ml)\n",
"\n",
"ml.write_input()\n",
"ml.run_model()\n",
"\n",
"hds = fu.HeadFile(os.path.join(workspace, name+'.hds'))\n",
"h = hds.get_data(kstpkper=(0, 0))\n",
"\n",
"x = y = np.linspace(0, L, N)\n",
"c = plt.contour(x, y, h[0], np.arange(90,100.1,0.2))\n",
"plt.clabel(c, fmt='%2.1f')\n",
"plt.axis('scaled');\n",
"plt.savefig(os.path.join(output, name+'_1.png'))\n",
"plt.close()\n",
"\n",
"x = y = np.linspace(0, L, N)\n",
"c = plt.contour(x, y, h[-1], np.arange(90,100.1,0.2))\n",
"plt.clabel(c, fmt='%1.1f')\n",
"plt.axis('scaled');\n",
"plt.savefig(os.path.join(output, name+'_2.png'))\n",
"plt.close()\n",
"\n",
"z = np.linspace(-H/Nlay/2, -H+H/Nlay/2, Nlay)\n",
"c = plt.contour(x, z, h[:,50,:], np.arange(90,100.1,.2))\n",
"plt.axis('scaled');\n",
"plt.savefig(os.path.join(output, name+'_3.png'))\n",
"plt.close()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading