-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from ArtesiaWater/dev
Release v0.4.0
- Loading branch information
Showing
81 changed files
with
4,955 additions
and
2,339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,333 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"<IMG SRC=\"https://avatars2.githubusercontent.com/u/31697400?s=400&u=a5a6fc31ec93c07853dd53835936fd90c44f7483&v=4\" WIDTH=125 ALIGN=\"right\">\n", | ||
"\n", | ||
"\n", | ||
"# Building a groundwater model from scratch with `nlmod`\n", | ||
"\n", | ||
"This notebook shows how to build a basic model from scratch using `nlmod`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import flopy as fp\n", | ||
"import matplotlib.pyplot as plt\n", | ||
"import nlmod\n", | ||
"import numpy as np\n", | ||
"import pandas as pd" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"nlmod.util.get_color_logger('INFO');" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Download MODFLOW-binaries\n", | ||
"To run MODFLOW, we need to download the MODFLOW-excecutables. We do this with the following code:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"if not nlmod.util.check_presence_mfbinaries():\n", | ||
" nlmod.util.download_mfbinaries()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Model parameters" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"extent = [-500, 500, -500, 500]\n", | ||
"\n", | ||
"top = 0.0\n", | ||
"botm = [-10, -15, -30]\n", | ||
"\n", | ||
"kh = [10, 0.1, 20]\n", | ||
"kv = [0.5 * k for k in kh]\n", | ||
"\n", | ||
"dx = 10.0\n", | ||
"dy = 10.0" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Create model dataset" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ds = nlmod.get_ds(\n", | ||
" extent,\n", | ||
" delr=dx,\n", | ||
" delc=dy,\n", | ||
" layer=len(kh),\n", | ||
" top=top,\n", | ||
" botm=botm,\n", | ||
" kh=kh,\n", | ||
" kv=kv,\n", | ||
" model_ws=\"./scratch_model\",\n", | ||
" model_name=\"from_scratch\",\n", | ||
")\n", | ||
"ds" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Set time discretisation" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ds = nlmod.time.set_ds_time(\n", | ||
" ds, time=[pd.Timestamp.today()], steady_state=True\n", | ||
")\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Start building model" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"sim = nlmod.sim.sim(ds)\n", | ||
"tdis = nlmod.sim.tdis(ds, sim)\n", | ||
"ims = nlmod.sim.ims(sim, complexity=\"SIMPLE\")\n", | ||
"gwf = nlmod.gwf.gwf(ds, sim)\n", | ||
"dis = nlmod.gwf.dis(ds, gwf)\n", | ||
"npf = nlmod.gwf.npf(ds, gwf)\n", | ||
"ic = nlmod.gwf.ic(ds, gwf, starting_head=1.0)\n", | ||
"oc = nlmod.gwf.oc(ds, gwf, save_head=True)\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Add wells" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"wells = pd.DataFrame(columns=[\"x\", \"y\", \"top\", \"botm\", \"Q\"], index=range(2))\n", | ||
"wells.index.name = \"well no.\"\n", | ||
"wells.loc[0] = 100, -50, -5, -10, -100.0\n", | ||
"wells.loc[1] = 200, 150, -20, -30, -300.0\n", | ||
"wells\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"wel = nlmod.gwf.wells.wel_from_df(wells, gwf)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Add river" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"xyriv = [\n", | ||
" (250, -500),\n", | ||
" (300, -300),\n", | ||
" (275, 0),\n", | ||
" (200, 250),\n", | ||
" (175, 500),\n", | ||
"]\n", | ||
"\n", | ||
"riv_layer = 0 # add to first layer\n", | ||
"\n", | ||
"bed_resistance = 0.1 # days\n", | ||
"riv_cond = dx * dy / bed_resistance # conductance\n", | ||
"riv_stage = 1.0 # m NAP\n", | ||
"riv_botm = -3.0 # m NAP" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"riv_data = nlmod.gwf.surface_water.rivdata_from_xylist( \n", | ||
" gwf, xyriv, riv_layer, riv_stage, riv_cond, riv_botm\n", | ||
")\n", | ||
"\n", | ||
"riv = fp.mf6.ModflowGwfriv(gwf, stress_period_data={0: riv_data})" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Write and run Simulation" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"nlmod.sim.write_and_run(sim, ds, silent=True)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Load heads" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"head = nlmod.util.get_heads_dataarray(ds)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Plot heads" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"fig, ax = plt.subplots(1, 1, figsize=(10, 8))\n", | ||
"\n", | ||
"pc = nlmod.plot.data_array(\n", | ||
" head.sel(layer=1).isel(time=0),\n", | ||
" ds=ds,\n", | ||
" cmap=\"RdYlBu\",\n", | ||
" ax=ax,\n", | ||
" edgecolor=\"k\",\n", | ||
")\n", | ||
"ax.axis(extent)\n", | ||
"cbar = ax.figure.colorbar(pc, shrink=1.0)\n", | ||
"cbar.set_label(\"head [m NAP]\")\n", | ||
"ax.set_title(\"head layer 1\")\n", | ||
"fig.tight_layout()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Plot heads in all layers" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"fig, axes = nlmod.plot.facet_plot(\n", | ||
" gwf,\n", | ||
" head,\n", | ||
" lbl=\"head [m NAP]\",\n", | ||
" plot_dim=\"layer\",\n", | ||
" period=0,\n", | ||
" cmap=\"RdYlBu\",\n", | ||
" plot_bc={\"WEL\": {}},\n", | ||
" plot_grid=True,\n", | ||
")" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"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.9.7" | ||
}, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "dace5e1b41a98a8e52d2a8eebc3b981caf2c12e7a76736ebfb89a489e3b62e79" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
Oops, something went wrong.