{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "a6513226-ab9a-4940-b64e-945f61cdae48",
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Exception reporting mode: Minimal\n"
]
}
],
"source": [
"%load_ext autoreload\n",
"%load_ext jbmagics\n",
"%autoreload 2"
]
},
{
"cell_type": "markdown",
"id": "a83e8653-936b-4fac-b858-36eb1f98814f",
"metadata": {},
"source": [
"# Inspect MODFLOW 6 interactively\n",
"\n",
"`pymf6` allows to access all MODFLOW 6 variables at run time.\n",
"First we import the class `MF6`:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "eccd36e0-66ac-42ae-bcd3-fe699dbd9107",
"metadata": {},
"outputs": [],
"source": [
"from pymf6.mf6 import MF6"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "38e9f6b0-1901-4b06-b260-f4cc87434329",
"metadata": {
"tags": [
"hide-cell",
"remove-cell"
]
},
"outputs": [],
"source": [
"MF6._demo = True"
]
},
{
"cell_type": "markdown",
"id": "8eb364a6-f109-4a13-8699-7777bb25e4dd",
"metadata": {},
"source": [
"We use a simple model:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "2026a190-708a-439d-a869-53ee80fc9a65",
"metadata": {},
"outputs": [],
"source": [
"nam_file = 'examples/head_controlled_well/models/pymf6/mfsim.nam'"
]
},
{
"cell_type": "markdown",
"id": "f41b604d-0187-4b1f-8d49-31881a4888e9",
"metadata": {},
"source": [
"and instantiate the class:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "e3c3233c-acb1-4e49-b3d3-3894b2bde91b",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Exception reporting mode: Verbose\n"
]
}
],
"source": [
"%xmode Verbose"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "cf83b05a-e791-40e9-9cd2-57400a4fa261",
"metadata": {},
"outputs": [],
"source": [
"mf6 = MF6(nam_file=nam_file)"
]
},
{
"cell_type": "markdown",
"id": "9458c9bf-cd7e-484f-8d03-2c658dffcf51",
"metadata": {},
"source": [
"The instance has HTML representation with some meta data: "
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "ce241a2e-4a30-453c-9f5f-8cff3f42a35d",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"
MF6
pymf6 configuration data
pymf6 version: | 1.0.4.dev3+g73beafa6 |
xmipy version: | 1.2.0 |
ini file path: | HOME/pymf6.ini |
dll file path: | path/to/dll/libmf6.dll |
MODFLOW version: | 6.4.1 |
MODFLOW variable documentation is available
"
],
"text/plain": [
""
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mf6"
]
},
{
"cell_type": "markdown",
"id": "221a244a-0060-4656-8987-0940de8465ee",
"metadata": {},
"source": [
"The same information is available as text: "
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "66ef23ab-e2f3-48c9-bf2c-02dd86b2c88b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"========================\n",
"pymf6 configuration data\n",
"========================\n",
"pymf6 version: 1.0.4.dev3+g73beafa6\n",
"xmipy version: 1.2.0\n",
"ini file path: HOME/pymf6.ini\n",
"dll file path: path/to/dll/libmf6.dll\n",
"MODFLOW version: 6.4.1\n",
"MODFLOW variable documentation is available\n"
]
}
],
"source": [
"mf6.info"
]
},
{
"cell_type": "markdown",
"id": "2fc05a70-6d24-4516-af24-ce42dfdad90a",
"metadata": {},
"source": [
"MODFLOW 6 supports multiple simulations.\n",
"This example only has one:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "5b2b24c1-2c39-45b4-b04e-2d38484cf077",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
"modeltype | \n",
"namefile | \n",
"modelname | \n",
"
\n",
" \n",
"\n",
"gwf6 | \n",
"headconwell.nam | \n",
"HEADCONWELL | \n",
"
\n",
"\n",
"
\n",
"
"
],
"text/plain": [
"=============================================\n",
"| modeltype | namefile | modelname |\n",
"---------------------------------------------\n",
"| gwf6 | headconwell.nam | HEADCONWELL |\n",
"============================================="
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mf6.simulation"
]
},
{
"cell_type": "markdown",
"id": "4dd7a689-ccf5-4ebe-930a-868f784d1302",
"metadata": {},
"source": [
"The names of the simulations are available as list of strings:"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "29005f4e-0ddf-4d27-8634-64b878d6c344",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['HEADCONWELL']"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mf6.simulation.model_names"
]
},
{
"cell_type": "markdown",
"id": "e96f8181-1aa9-47eb-857f-20cee03c0579",
"metadata": {},
"source": [
"The models have their own representations:"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "f0b09955-26cf-400d-b00f-14ee3e578853",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[Model HEADCONWELL \n",
" 15 packages\n",
" 49 variables.]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mf6.simulation.models"
]
},
{
"cell_type": "markdown",
"id": "9be71b23-8165-4db5-99da-1823860fd096",
"metadata": {},
"source": [
"The meta information is also available as a dictionary:"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "b0626be0-123e-409b-9d69-80869428c3d9",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[{'modeltype': 'gwf6',\n",
" 'namefile': 'headconwell.nam',\n",
" 'modelname': 'HEADCONWELL'}]"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mf6.simulation.models_meta"
]
},
{
"cell_type": "markdown",
"id": "0ef2987b-1af9-4895-89d6-689bda8bbae5",
"metadata": {},
"source": [
"This example only one solution group:"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "f5ffbdf7-5cf4-4931-ad78-8c80feb8b63c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[Solution 1 \n",
" 1 packages\n",
" 68 variables.]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mf6.simulation.solution_groups"
]
},
{
"cell_type": "markdown",
"id": "0f15cc30-05d3-494d-bea3-45eec5c5aeb5",
"metadata": {},
"source": [
"This is the time discretization is: "
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "05d1e2a1-e8b5-4eea-8056-493adcb4c99e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Package TDIS
"
],
"text/plain": [
"Package TDIS \n",
"19 variables."
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mf6.simulation.TDIS"
]
},
{
"cell_type": "markdown",
"id": "81027dd3-b4bb-4add-86bd-7298bc456d59",
"metadata": {},
"source": [
"These are the names of the variables:"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "59c21009-117f-4af8-a820-9447030b73b6",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['NPER',\n",
" 'ITMUNI',\n",
" 'KPER',\n",
" 'KSTP',\n",
" 'INATS',\n",
" 'READNEWDATA',\n",
" 'ENDOFPERIOD',\n",
" 'ENDOFSIMULATION',\n",
" 'DELT',\n",
" 'PERTIM',\n",
" 'TOTIM',\n",
" 'TOTIMC',\n",
" 'DELTSAV',\n",
" 'TOTIMSAV',\n",
" 'PERTIMSAV',\n",
" 'TOTALSIMTIME',\n",
" 'PERLEN',\n",
" 'NSTP',\n",
" 'TSMULT']"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mf6.simulation.TDIS.var_names"
]
},
{
"cell_type": "markdown",
"id": "73fa325d-77ec-4fb5-8f73-9fb354119f46",
"metadata": {},
"source": [
"There a scalar values:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "e207056d-311d-4dc5-95f6-4156e6d8c668",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Variable NPER
value: | 4 |
docstring: | set equal to nper |
docstring source: | src/Timing/ats.f90\n",
" line 25 |
docstring: | number of stress period |
docstring source: | src/Timing/tdis.f90\n",
" line 22 |
"
],
"text/plain": [
"Variable NPER \n",
"value: 4\n",
"docstring: set equal to nper\n",
"docstring source: src/Timing/ats.f90 line 25\n",
"docstring: number of stress period\n",
"docstring source: src/Timing/tdis.f90 line 22"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mf6.simulation.TDIS.NPER"
]
},
{
"cell_type": "markdown",
"id": "26bdbe41-d07e-4d40-a640-428877a03c3c",
"metadata": {},
"source": [
"and arrays:"
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "56748504-c16f-4927-9515-0c93609e1cbc",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Variable PERLEN
value: | array([ 1., 10., 10., 10.]) |
shape: | (4,) |
docstring: | length of each stress period |
docstring source: | src/Timing/tdis.f90\n",
" line 38 |
"
],
"text/plain": [
"Variable PERLEN \n",
"value: array([ 1., 10., 10., 10.])\n",
"shape: (4,)\n",
"docstring: length of each stress period\n",
"docstring source: src/Timing/tdis.f90 line 38"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mf6.simulation.TDIS.PERLEN"
]
},
{
"cell_type": "markdown",
"id": "350ba9d6-6898-49c4-bd77-b5a2da59f112",
"metadata": {},
"source": [
"The docstrings are extracted from the MODFLOW 6 source code from the\n",
"used MODFLOW version as displayed with `mf6.info`."
]
},
{
"cell_type": "markdown",
"id": "ecb97b5f-77ac-4b06-b0f8-6ddea0621b20",
"metadata": {},
"source": [
"The instance has many variables:"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "74025227-0e89-409b-a270-01c8968592d8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"529"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(mf6.vars)"
]
},
{
"cell_type": "markdown",
"id": "57222ffb-4d57-4ab6-81a1-dea476dfd4ff",
"metadata": {},
"source": [
"Filter for all `TDIS` entries:"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "ca87bdde-d42a-4715-a2f1-29afc4aaf7f0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'TDIS/NPER': array([4], dtype=int32),\n",
" 'TDIS/ITMUNI': array([4], dtype=int32),\n",
" 'TDIS/KPER': array([0], dtype=int32),\n",
" 'TDIS/KSTP': array([0], dtype=int32),\n",
" 'TDIS/INATS': array([0], dtype=int32),\n",
" 'TDIS/DELT': array([0.]),\n",
" 'TDIS/PERTIM': array([0.]),\n",
" 'TDIS/TOTIM': array([0.]),\n",
" 'TDIS/TOTIMC': array([0.]),\n",
" 'TDIS/DELTSAV': array([0.]),\n",
" 'TDIS/TOTIMSAV': array([0.]),\n",
" 'TDIS/PERTIMSAV': array([0.]),\n",
" 'TDIS/TOTALSIMTIME': array([31.]),\n",
" 'TDIS/PERLEN': array([ 1., 10., 10., 10.]),\n",
" 'TDIS/NSTP': array([ 1, 120, 120, 120], dtype=int32),\n",
" 'TDIS/TSMULT': array([1., 1., 1., 1.])}"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"{k: v for k, v in mf6.vars.items() if 'TDIS' in k}"
]
},
{
"cell_type": "markdown",
"id": "50342c44-9e11-4b59-a609-17db6edd1984",
"metadata": {},
"source": [
"Show the first 50:"
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "3bcf0080-310d-4e2b-aaa0-922e40320ba8",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'TDIS/NPER': array([4], dtype=int32),\n",
" 'TDIS/ITMUNI': array([4], dtype=int32),\n",
" 'TDIS/KPER': array([0], dtype=int32),\n",
" 'TDIS/KSTP': array([0], dtype=int32),\n",
" 'TDIS/INATS': array([0], dtype=int32),\n",
" 'TDIS/DELT': array([0.]),\n",
" 'TDIS/PERTIM': array([0.]),\n",
" 'TDIS/TOTIM': array([0.]),\n",
" 'TDIS/TOTIMC': array([0.]),\n",
" 'TDIS/DELTSAV': array([0.]),\n",
" 'TDIS/TOTIMSAV': array([0.]),\n",
" 'TDIS/PERTIMSAV': array([0.]),\n",
" 'TDIS/TOTALSIMTIME': array([31.]),\n",
" 'TDIS/PERLEN': array([ 1., 10., 10., 10.]),\n",
" 'TDIS/NSTP': array([ 1, 120, 120, 120], dtype=int32),\n",
" 'TDIS/TSMULT': array([1., 1., 1., 1.]),\n",
" 'HEADCONWELL/ID': array([1], dtype=int32),\n",
" 'HEADCONWELL/IOUT': array([1005], dtype=int32),\n",
" 'HEADCONWELL/INEWTON': array([0], dtype=int32),\n",
" 'HEADCONWELL/IPRPAK': array([0], dtype=int32),\n",
" 'HEADCONWELL/IPRFLOW': array([0], dtype=int32),\n",
" 'HEADCONWELL/IPAKCB': array([-1], dtype=int32),\n",
" 'HEADCONWELL/IDSOLN': array([1], dtype=int32),\n",
" 'HEADCONWELL/NEQ': array([100], dtype=int32),\n",
" 'HEADCONWELL/NJA': array([460], dtype=int32),\n",
" 'HEADCONWELL/ICNVG': array([0], dtype=int32),\n",
" 'HEADCONWELL/MOFFSET': array([0], dtype=int32),\n",
" 'HEADCONWELL/INIC': array([1007], dtype=int32),\n",
" 'HEADCONWELL/INOC': array([1012], dtype=int32),\n",
" 'HEADCONWELL/INNPF': array([1008], dtype=int32),\n",
" 'HEADCONWELL/INBUY': array([0], dtype=int32),\n",
" 'HEADCONWELL/INVSC': array([0], dtype=int32),\n",
" 'HEADCONWELL/INSTO': array([1009], dtype=int32),\n",
" 'HEADCONWELL/INCSUB': array([0], dtype=int32),\n",
" 'HEADCONWELL/INMVR': array([0], dtype=int32),\n",
" 'HEADCONWELL/INHFB': array([0], dtype=int32),\n",
" 'HEADCONWELL/INGNC': array([0], dtype=int32),\n",
" 'HEADCONWELL/INOBS': array([0], dtype=int32),\n",
" 'HEADCONWELL/ISS': array([0], dtype=int32),\n",
" 'HEADCONWELL/INEWTONUR': array([0], dtype=int32),\n",
" 'HEADCONWELL/DIS/INUNIT': array([1006], dtype=int32),\n",
" 'HEADCONWELL/DIS/IOUT': array([1005], dtype=int32),\n",
" 'HEADCONWELL/DIS/NODES': array([100], dtype=int32),\n",
" 'HEADCONWELL/DIS/NODESUSER': array([100], dtype=int32),\n",
" 'HEADCONWELL/DIS/NDIM': array([3], dtype=int32),\n",
" 'HEADCONWELL/DIS/ICONDIR': array([1], dtype=int32),\n",
" 'HEADCONWELL/DIS/NOGRB': array([0], dtype=int32),\n",
" 'HEADCONWELL/DIS/XORIGIN': array([0.]),\n",
" 'HEADCONWELL/DIS/YORIGIN': array([0.]),\n",
" 'HEADCONWELL/DIS/ANGROT': array([0.])}"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dict(list(mf6.vars.items())[:50])"
]
},
{
"cell_type": "markdown",
"id": "9cf336f9-f7f9-4a53-823a-5cefad6aba7a",
"metadata": {},
"source": [
"Many values are still zero.\n",
"We can get the time steps:"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "25233a3e-3e14-400c-8d67-950fa31dc809",
"metadata": {},
"outputs": [],
"source": [
"steps = mf6.steps()"
]
},
{
"cell_type": "markdown",
"id": "c70d7b97-a4b4-49e9-b0db-51b613da2bf4",
"metadata": {},
"source": [
"We can do single time steps:"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "8f38c556-c5d2-4cd8-9224-25edaeac72e0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.0"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"next(steps)"
]
},
{
"cell_type": "markdown",
"id": "e7ec3fe1-528e-45c9-925f-c7961f24cdc6",
"metadata": {},
"source": [
"Now, the values have changed:"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "50b5c41a-699c-4ed5-9f90-b453736fddeb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'TDIS/NPER': array([4], dtype=int32),\n",
" 'TDIS/ITMUNI': array([4], dtype=int32),\n",
" 'TDIS/KPER': array([1], dtype=int32),\n",
" 'TDIS/KSTP': array([1], dtype=int32),\n",
" 'TDIS/INATS': array([0], dtype=int32)}"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"dict(list(mf6.vars.items())[:5])"
]
},
{
"cell_type": "markdown",
"id": "4702cf1c-078b-4216-90b3-0d8db15ec191",
"metadata": {},
"source": [
"We can get access to well rates:"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "b569252d-01fb-46a8-b356-a50cd638aec5",
"metadata": {},
"outputs": [],
"source": [
"wel = mf6.vars['HEADCONWELL/WEL_0/BOUND']"
]
},
{
"cell_type": "markdown",
"id": "90b0b9c6-daec-471d-bcbf-1b60f6a5284b",
"metadata": {},
"source": [
"This model has only one well:"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "dd7b3058-02d5-438e-ab45-fdc33efff3ab",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.]])"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"wel"
]
},
{
"cell_type": "markdown",
"id": "0549c13f-59a5-4bee-b87b-7a14d91d81c2",
"metadata": {},
"source": [
"The first stress period is steady state hand has not well extraction rate.\n",
"Doing the next steps will go the next stress period with a rate:"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "5aa46f66-2330-4a6b-9244-d343d28a3f44",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.0"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"next(steps)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "e24fc913-038e-4e57-a67b-02a3f4970a8b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[-0.05]])"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"wel"
]
},
{
"cell_type": "markdown",
"id": "e3a913e9-bd48-43af-aaf8-3f804bf5474c",
"metadata": {},
"source": [
"Fast forward to next stress period, i.e. to day 11:"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "446fe1c3-df6a-4484-a7ff-f1422128b785",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Variable PERLEN
value: | array([ 1., 10., 10., 10.]) |
shape: | (4,) |
docstring: | length of each stress period |
docstring source: | src/Timing/tdis.f90\n",
" line 38 |
"
],
"text/plain": [
"Variable PERLEN \n",
"value: array([ 1., 10., 10., 10.])\n",
"shape: (4,)\n",
"docstring: length of each stress period\n",
"docstring source: src/Timing/tdis.f90 line 38"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mf6.simulation.TDIS.PERLEN"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "9d560ab0-23a6-429d-a6df-6a2266b908ac",
"metadata": {},
"outputs": [],
"source": [
"for step in steps:\n",
" if step > 11:\n",
" break"
]
},
{
"cell_type": "markdown",
"id": "5e1bcbe0-dacc-4563-a2fc-52959aa52f88",
"metadata": {},
"source": [
"Now the value has changed:"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "69683319-49c7-4661-9fee-d78109f5c1ce",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"array([[-0.5]])"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"wel"
]
}
],
"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.11.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}