diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 937a35e554a..e49f7c8edb7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,11 +71,66 @@ jobs: - name: Meson test run: meson test --verbose --no-rebuild -C builddir + smoke_test: + name: Smoke test (gfortran 12) + runs-on: ubuntu-22.04 + defaults: + run: + shell: bash -l {0} + env: + FC: gfortran + GCC_V: 12 + steps: + - name: Checkout modflow6 + uses: actions/checkout@v3 + with: + path: modflow6 + + - name: Setup GNU Fortran ${{ env.GCC_V }} + uses: awvwgk/setup-fortran@main + with: + compiler: gcc + version: ${{ env.GCC_V }} + + - name: Setup Micromamba + uses: mamba-org/provision-with-micromamba@main + with: + environment-file: modflow6/environment.yml + cache-downloads: true + cache-env: true + + - name: Build modflow6 + working-directory: modflow6 + run: | + meson setup builddir -Ddebug=false --prefix=$(pwd) --libdir=bin + meson install -C builddir + meson test --verbose --no-rebuild -C builddir + + - name: Update flopy + working-directory: modflow6/autotest + run: python update_flopy.py + + - name: Get executables + working-directory: modflow6/autotest + env: + GITHUB_TOKEN: ${{ github.token }} + run: pytest -v --durations 0 get_exes.py + + - name: Test programs + working-directory: modflow6/autotest + run: | + if [ "${{ github.ref_name }}" == "master" ]; then + pytest -v -n auto --durations 0 -m "not slow and not regression and not developmode" + else + pytest -v -n auto --durations 0 -S + fi + test_gfortran_latest: name: Test (gfortran 12) needs: - lint - build + - smoke_test runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -131,6 +186,8 @@ jobs: - name: Test programs working-directory: modflow6/autotest + env: + REPOS_PATH: ${{ github.workspace }} run: | if [ "${{ github.ref_name }}" == "master" ]; then pytest -v -n auto --durations 0 -m "not large and not developmode" @@ -149,6 +206,7 @@ jobs: needs: - lint - build + - smoke_test runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -205,6 +263,8 @@ jobs: - name: Test modflow6 working-directory: modflow6/autotest + env: + REPOS_PATH: ${{ github.workspace }} run: | if [ "${{ github.ref_name }}" == "master" ]; then pytest -v -n auto --durations 0 -m "not large and not developmode" @@ -217,6 +277,7 @@ jobs: needs: - lint - build + - smoke_test runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -299,6 +360,8 @@ jobs: - name: Test programs if: runner.os != 'Windows' working-directory: modflow6/autotest + env: + REPOS_PATH: ${{ github.workspace }} run: | if [ "${{ github.ref_name }}" == "master" ]; then pytest -v -n auto --durations 0 -m "not large and not developmode" @@ -310,6 +373,8 @@ jobs: if: runner.os == 'Windows' working-directory: modflow6/autotest shell: pwsh + env: + REPOS_PATH: ${{ github.workspace }} run: | if ( "${{ github.ref_name }}" -eq "master" ) { pytest -v -n auto --durations 0 -m "not large and not developmode" diff --git a/DEVELOPER.md b/DEVELOPER.md index 78272df0b10..39207e4c0f5 100644 --- a/DEVELOPER.md +++ b/DEVELOPER.md @@ -1,64 +1,84 @@ # Developing MODFLOW 6 -This document describes how to set up your development environment to build and test MODFLOW 6. -It also explains the basic mechanics of using `git`. Details on how to contribute your code to the repository are found in the separate document [CONTRIBUTING.md](CONTRIBUTING.md). +This document describes how to set up a development environment to modify, build and test MODFLOW 6. Details on how to contribute your code to the repository are found in the separate document [CONTRIBUTING.md](CONTRIBUTING.md). -- [Requirements](#requirements) +- [Prerequisites](#prerequisites) - [Git](#git) - - [gfortran (version 4.9 to 10)](#gfortran-version-49-to-10) - - [Linux](#linux) - - [macOS](#macos) - - [Windows](#windows) + - [Fortran compiler](#fortran-compiler) + - [GNU Fortran](#gnu-fortran) + - [Linux](#linux) + - [macOS](#macos) + - [Windows](#windows) + - [Intel Fortran](#intel-fortran) + - [Windows](#windows-1) - [Python](#python) - - [ifort (optional)](#ifort-optional) - - [Windows](#windows-1) - - [Doxygen & LaTeX (optional)](#doxygen--latex-optional) - - [fprettify](#fprettify) + - [Dependencies](#dependencies) + - [`meson`](#meson) + - [`fprettify`](#fprettify) + - [`mfpymake`](#mfpymake) + - [`flopy`](#flopy) + - [`modflow-devtools`](#modflow-devtools) + - [Optional tools](#optional-tools) + - [GNU Make](#gnu-make) + - [Visual Studio](#visual-studio) + - [Doxygen & LaTeX](#doxygen--latex) - [Installation](#installation) - [Building](#building) - - [Meson](#meson) - - [Visual Studio](#visual-studio) - - [Pymake](#pymake) - - [Make](#make) - [Testing](#testing) - - [External model repos](#external-model-repos) + - [Configuring a test environment](#configuring-a-test-environment) + - [Building development binaries](#building-development-binaries) + - [Rebuilding and installing release binaries](#rebuilding-and-installing-release-binaries) + - [Updating `flopy` plugins](#updating-flopy-plugins) + - [External model repositories](#external-model-repositories) - [Installing external repos](#installing-external-repos) - [Test models](#test-models) - [Example models](#example-models) - - [Running external model tests](#running-external-model-tests) + - [Running Tests](#running-tests) + - [Selecting tests with markers](#selecting-tests-with-markers) + - [External model tests](#external-model-tests) + - [Writing tests](#writing-tests) -## Requirements +## Prerequisites Before you can build and test MODFLOW 6, you must install and configure the -following products on your development machine. +following on your development machine: + +- git +- Python3.8+ +- a modern Fortran compiler + +Some additional, optional tools are also discussed below. ### Git [Git](https://git-scm.com) and/or the **GitHub app** (for [Mac](https://mac.github.com) or [Windows](https://windows.github.com)). [GitHub's Guide to Installing Git](https://help.github.com/articles/set-up-git) is a good source of information. +### Fortran compiler + +The GNU Fortran compiler `gfortran` or the Intel Fortran compiler `ifort` can be used to compile MODFLOW 6. -### gfortran (version 4.9 to 10) +#### GNU Fortran -gfortran can be used to compile MODFLOW 6 and associated utilities and generate distributable files. +GNU Fortran can be installed on all three major platforms. -#### Linux +##### Linux - fedora-based: `dnf install gcc-gfortran` - debian-based: `apt install gfortran` -#### macOS +##### macOS - [Homebrew](https://brew.sh/): `brew install gcc` - [MacPorts](https://www.macports.org/): `sudo port install gcc10` -#### Windows +##### Windows - Download the Minimalist GNU for Windows (MinGW) installer from Source Forge: https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe @@ -70,45 +90,95 @@ gfortran can be used to compile MODFLOW 6 and associated utilities and generate `Path` variable in the User Variables (the top table). Click the `New` button and enter the location of the `mingw64/bin` directory. +#### Intel Fortran + +Intel Fortran can also be used to compile MODFLOW 6 and associated utilities. The `ifort` compiler is available in the [Intel oneAPI HPC Toolkit](https://software.intel.com/content/www/us/en/develop/tools/oneapi/hpc-toolkit/download.html). An installer is bundled with the download. A minimal + +A number of environment variables must be set before using Intel Fortran. General information can be found [here](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup.html), with specific instructions to configure a shell session for `ifort` [here](https://www.intel.com/content/www/us/en/develop/documentation/fortran-compiler-oneapi-dev-guide-and-reference/top/compiler-setup/use-the-command-line/specifying-the-location-of-compiler-components.html). + +##### Windows + +On Windows, [Visual Studio](https://visualstudio.microsoft.com) and a number of libraries must be installed for `ifort` to work. The required libraries can be installed by ticking the "Desktop Development with C++" checkbox in the Visual Studio Installer's Workloads tab. + +**Note:** Invoking the `setvars.bat` scripts from a Powershell session will *not* put `ifort` on the path, since [batch script environments are local to their process](https://stackoverflow.com/a/49028002/6514033). Either invoke `ifort` from command prompt or relaunch PowerShell, e.g. + +``` +cmd.exe "/K" '"C:\Program Files (x86)\Intel\oneAPI\setvars-vcvarsall.bat" && "C:\Program Files (x86)\Intel\oneAPI\compiler\latest\env\vars.bat" && powershell' +``` + ### Python -Install Python, for example via [miniconda](https://docs.conda.io/en/latest/miniconda.html) or [Anaconda](https://www.anaconda.com/products/individual). -Then create a new environment by executing the following at the root of this repository +Python 3.8+ is required to run MODFLOW 6 tests. A Conda distribution (e.g. [miniconda](https://docs.conda.io/en/latest/miniconda.html) or [Anaconda](https://www.anaconda.com/products/individual) is recommended. Python dependencies are specified in `environment.yml`. To create an environment, run from the project root: + ``` -conda env create --force -f environment.yml +conda env create -f environment.yml ``` -### ifort (optional) +To update an existing environment: -Intel fortran can be used to compile MODFLOW 6 and associated utilities and generate distributable files (if not using gfortran). -Download the Intel oneAPI HPC Toolkit: https://software.intel.com/content/www/us/en/develop/tools/oneapi/hpc-toolkit/download.html +```shell +conda env update -f environment.yml +``` -Documentation describing how to set the intel environment variables can be found [here](https://www.intel.com/content/www/us/en/develop/documentation/oneapi-programming-guide/top/oneapi-development-environment-setup.html). +#### Dependencies -#### Windows +This project depends critically on a few Python packages for building, linting and testing tasks: -- Visual Studio with the appropriate redistributable libraries must be installed for ifort to compile on Windows. -- Install Visual Studio, which can be found [here](https://visualstudio.microsoft.com/). Note: the latest version of Visual Studio, 2022, requires a sufficiently new version of the Intel OneAPI as well. -- The redistributable libraries can installed via ticking the "Desktop Development with C++" checkbox in the Visual Studio Installer in the Workloads tab. +- `meson` +- `fprettify` +- `pymake` +- `flopy` -### Doxygen & LaTeX (optional) +These are each described briefly below. The Conda `environment.yml` contains a number of other dependencies also required for various development tasks, but they are not described in detail here. -[Doxygen](https://www.doxygen.nl/index.html) is used to generate the [MODFLOW 6 source code documentation](https://modflow-usgs.github.io/modflow6/). [Graphviz](https://graphviz.org/) is used by doxygen to produce source code diagrams. [LaTeX](https://www.latex-project.org/) is used to generate the MODFLOW 6 release notes and Input/Output documents (docs/mf6io/mf6io.nightlybuild). -These programs can be installed from various sources, including by conda, macports, or from individual sources such as https://www.tug.org/. Details about USGS LaTeX libraries can be seen in addition to linux installs in the CI workflow for the docs (`.github/workflows/ci-docs.yml`). +##### `meson` + +[Meson](https://mesonbuild.com/index.html) is recommended for building MODFLOW 6 and is included in `environment.yml`. It can also be [installed independently](https://mesonbuild.com/Getting-meson.html) — note that if you do so you will need to manually add the executable to the [PATH](https://en.wikipedia.org/wiki/PATH_(variable)). + +##### `fprettify` + +[`fprettify`](https://github.com/pseewald/fprettify) can be used to format Fortran source code and in combination with the [MODFLOW 6 fprettify configuration](https://github.com/MODFLOW-USGS/modflow6/blob/develop/distribution/.fprettify.yaml) establishes a contribution standard for properly formatted MODFLOW 6 Fortran source. This tool can be installed with `pip` or `conda` and used from the command line or integrated with a [VSCode](https://github.com/MODFLOW-USGS/modflow6/blob/develop/.vscode/README.md) or Visual Studio development environment. The `fprettify` package is included in the Conda environment in `environment.yml`. See [contribution guidelines](https://github.com/MODFLOW-USGS/modflow6/blob/develop/CONTRIBUTING.md) for additional information. + +##### `mfpymake` + +The `mfpymake` package can build MODFLOW 6 and related programs and artifacts (e.g. makefiles), and is used in particular by the `distribution/build_makefiles.py` script. `mfpymake` is included in the Conda environment in `environment.yml`. To install separately, follow the instructions as explained on the README of the [repository](https://github.com/modflowpy/pymake). The README also demonstrates basic usage. -### fprettify +##### `flopy` -[fprettify](https://github.com/pseewald/fprettify) can be used to format Fortran source code and in combination with the [MODFLOW 6 fprettify configuration](https://github.com/MODFLOW-USGS/modflow6/blob/develop/distribution/.fprettify.yaml) establishes a contribution standard for properly formatted MODFLOW 6 Fortran source. This tool can be installed with `pip` or `conda` and used from the command line or integrated with a [VSCode](https://github.com/MODFLOW-USGS/modflow6/blob/develop/.vscode/README.md) or Visual Studio development environment. See [contribution guidelines](https://github.com/MODFLOW-USGS/modflow6/blob/develop/CONTRIBUTING.md) for additional information. +[`flopy`](https://github.com/modflowpy/flopy) is used throughout MODFLOW 6 tests to create, run and post-process models. + +Like MODFLOW 6, `flopy` is modular — for each MODFLOW 6 package there is generally a corresponding `flopy` plugin. Plugins are generated dynamically from DFN files stored in this repository under `doc/mf6io/mf6ivar/dfn`. + +##### `modflow-devtools` + +The tests use a set of shared fixtures and utilities provided by the [`modflow-devtools`](https://github/com/MODFLOW-USGS/modflow-devtools) package. This package is included in the Conda environment in `environment.yml`. + +### Optional tools + +Some other tools are useful but not required to develop MODFLOW 6. + +#### GNU Make + +This repository provides makefiles, generated by `mfpymake`, which can be used to build MODFLOW 6 with [GNU Make](https://www.gnu.org/software/make/). For further instructions we refer to the [GNU Make Manual](https://www.gnu.org/software/make/manual/). + +#### Visual Studio + +Visual Studio installers can be downloaded from the [official website](https://visualstudio.microsoft.com/). MODFLOW 6 solution files can be found in the `msvs` folder. + +#### Doxygen & LaTeX + +[Doxygen](https://www.doxygen.nl/index.html) is used to generate the [MODFLOW 6 source code documentation](https://modflow-usgs.github.io/modflow6/). [Graphviz](https://graphviz.org/) is used by doxygen to produce source code diagrams. [LaTeX](https://www.latex-project.org/) is used to generate the MODFLOW 6 release notes and Input/Output documents (docs/mf6io/mf6io.nightlybuild). + +These programs can be installed from various sources, including by conda, macports, or from individual sources such as https://www.tug.org/. Details about USGS LaTeX libraries can be seen in addition to linux installs in the CI workflow for the docs (`.github/workflows/ci-docs.yml`). ## Installation Fork and clone the MODFLOW 6 repository: -1. Login to your GitHub account or create one by following the instructions given - [here](https://github.com/signup/free). +1. Login to your GitHub account or create one by following the instructions given [here](https://github.com/signup/free). 2. [Fork](http://help.github.com/forking) the [main MODFLOW 6](https://github.com/MODFLOW-USGS/modflow6). -3. Clone your fork of the MODFLOW 6 repository and define an `upstream` remote pointing back to the MODFLOW 6 repository that you forked in the first place. +3. Clone your fork of the MODFLOW 6 repository and create an `upstream` remote pointing back to your fork. ```shell # Clone your GitHub repository: @@ -123,15 +193,15 @@ git remote add upstream https://github.com/MODFLOW-USGS/modflow6.git ## Building -### Meson +Meson is the recommended build tool for MODFLOW 6. [Meson](https://mesonbuild.com/Getting-meson.html) must be installed and on your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)). Creating and activating the Conda environment `environment.yml` should be sufficient for this. -First, install [Meson](https://mesonbuild.com/Getting-meson.html) and assure it is in your [PATH](https://en.wikipedia.org/wiki/PATH_(variable)). -When using Visual Studio Code, you can use tasks as described [here](.vscode/README.md). -For the more general instructions, continue to read this section. +Meson build configuration files are provided for MODFLOW 6 as well as `zbud6` and `mf5to6` utility programs: -First configure the build directory. -Per default it uses the compiler flags for a release build. -If you want to create a debug build, add `-Doptimization=0` to the following `setup` command. +- `meson.build` +- `utils/zonebudget/meson.build` +- `utils/mf5to6/meson.build` + +To build MODFLOW 6, first configure the build directory. By default Meson uses compiler flags for a release build. To create a debug build, add `-Doptimization=0` to the following `setup` command. ```shell # bash (linux and macOS) @@ -153,71 +223,82 @@ In order to run the tests the binaries have to be installed: meson install -C builddir ``` -The binaries can then be found in the `bin` folder. -`meson install` also triggers a compilation if necessary. -Therefore, executing `meson install` is enough to get up-to-date binaries in the `bin` folder. +The binaries can then be found in the `bin` folder. `meson install` also triggers a compilation if necessary, so executing `meson install` is enough to get up-to-date binaries in the `bin` folder. + +**Note:** If using Visual Studio Code, you can use tasks as described [here](.vscode/README.md) to automate the above. -### Visual Studio +## Testing -As of October 2021, debugging with Visual Studio tends to be more convenient than with other solutions. -First, download Visual Studio from the [official website](https://visualstudio.microsoft.com/). -The solution files can be found in the `msvs` folder. +MODFLOW 6 tests are driven with [`pytest`](https://docs.pytest.org/en/7.1.x/), with the help of plugins like `pytest-xdist` and `pytest-cases`. Testing dependencies are included in the Conda environment `environment.yml`. -### Pymake +**Note:** the entire test suite should pass before a pull request is submitted. Tests run in GitHub Actions CI and a PR can only be merged with passing tests. See [`CONTRIBUTING.md`](CONTRIBUTING.md) for more information. -Follow the installation instructions as explained on the README of the [repository](https://github.com/modflowpy/pymake). -The README also explains how to build MODFLOW 6 with it. +### Configuring a test environment -### Make +A few tasks must be completed before running tests: -We also provide make files which can be used to build MODFLOW 6 with [GNU Make](https://www.gnu.org/software/make/). -For the build instructions we refer to the [GNU Make Manual](https://www.gnu.org/software/make/manual/). +- build local MODFLOW 6 development version +- rebuild the last MODFLOW 6 release +- install additional executables +- update FloPy plugins +- clone MODFLOW 6 test model and example repositories -## Testing +Tests expect binaries to live in the `bin` directory relative to the project root, as configured above in the `meson` commands. Binaries are organized as follows: -Tests should pass locally before a PR is opened on Github. All the tests are executed by the CI system and a pull request can only be merged with passing tests. +- local development binaries in the top-level `bin` folder +- executables rebuilt in development mode from the latest release in `bin/rebuilt` +- related programs installed from the [executables distribution](https://github.com/MODFLOW-USGS/executables/releases) live in `bin/downloaded` Tests must be run from the `autotest` folder. -```shell -cd autotest -``` +#### Building development binaries -FloPy plugins must first be updated: +Before running tests, the local development version of MODFLOW 6 must be built with `meson` as described above. The `autotest/build_exes.py` script is provided as a shortcut to easily rebuild local binaries. The script can be run from the project root with: ```shell -python update_flopy.py +python autotest/build_exes.py ``` -The tests require other MODFLOW-related binary executables, distributed from https://github.com/MODFLOW-USGS/executables. -Testing also requires a binary executable of the last MODFLOW 6 officially released version, compiled in develop mode with the currently configured compiler. To download MODFLOW-related binaries and to rebuild the last official MODFLOW 6 release, execute: +Alternatively, it can be run from the `autotest` directory with `pytest`: ```shell -pytest -v get_exes.py +pytest build_exes.py ``` -Unless you built and installed MODFLOW 6 binaries with meson, you will also have to execute the following command to build the binaries: +By default, binaries will be placed in the `bin` directory relative to the project root, as in the `meson` commands described above. To change the location of the binaries, use the `--path` option. + +#### Rebuilding and installing release binaries + +Tests require the latest official MODFLOW 6 release to be compiled in develop mode with the same Fortran compiler as the development version. A number of binaries distributed from the [executables repo](https://github.com/MODFLOW-USGS/executables) must also be installed. The script `autotest/get_exes.py` does both of these things. It can be run from the project root with: ```shell -pytest -v build_exes.py +python autotest/get_exes.py ``` -Then the tests can be run with `pytest` as usual, for instance: +Alternatively, with `pytest` from the `autotest` directory: ```shell -# Run all tests with verbose output -pytest -v +pytest get_exes.py ``` -Tests can be run in parallel with the `-n` option, which accepts an integer argument for the number of processes to use. If the value `auto` is provided, `pytest-xdist` will use as many processes as your machine has available CPUs: +By default, binaries will be placed in the `bin` directory relative to the project root, as in the `meson` commands described above. Nested `bin/downloaded` and `bin/rebuilt` directories are created to contain the rebuilt last release and the downloaded executables, respectively. To change the location of the binaries, use the `--path` option. + +#### Updating `flopy` plugins + +Plugins should be regenerated from DFN files before running tests for the first time or after definition files change. This can be done with the `autotest/update_flopy.py` script, which wipes and regenerates plugin classes for the `flopy` installed in the Python environment. + +**Note:** if you've installed a local version of `flopy` from source, running this script can overwrite files in your repository. + +There is a single optional argument, the path to the folder containing definition files. By default DFN files are assumed to live in `doc/mf6io/mf6ivar/dfn`, making the following identical: ```shell -pytest -v -n auto +python autotest/update_flopy.py +python autotest/update_flopy.py doc/mf6io/mf6ivar/dfn ``` -### External model repos +#### External model repositories -While many tests create models programmatically, the full suite tests MODFLOW 6 against example models stored in the following external repositories: +Some autotests load example models from external repositories: - [`MODFLOW-USGS/modflow6-testmodels`](https://github.com/MODFLOW-USGS/modflow6-testmodels) - [`MODFLOW-USGS/modflow6-largetestmodels`](https://github.com/MODFLOW-USGS/modflow6-largetestmodels) @@ -261,20 +342,84 @@ python ci_build_files.py This will build the examples for subsequent use by the tests. -#### Running external model tests +### Running Tests + +Tests are driven by `pytest` and must be run from the `autotest` folder. To run tests in a particular file, showing verbose output, use: + +```shell +pytest -v +``` + +Tests can be run in parallel with the `-n` option, which accepts an integer argument for the number of parallel processes. If the value `auto` is provided, `pytest-xdist` will use one worker per available processor. + +```shell +pytest -v -n auto +``` + +#### Selecting tests with markers + +Markers can be used to select subsets of tests. Markers provided in `pytest.ini` include: + +- `slow`: tests that take longer than a few seconds to complete +- `repo`: tests that require external model repositories +- `large`: tests using large models (from the `modflow6-examples` and `modflow6-largetestmodels` repos) +- `regression`: tests comparing results from multiple versions + +Markers can be used with the `-m ` option, and can be applied in boolean combinations with `and`, `or` and `not`. For instance, to run fast tests in parallel, excluding regression tests: + +```shell +pytest -v -n auto -m "not slow and not regression" +``` + +The `--smoke` (short `-S`) flag, provided by `modflow-devtools` is an alias for the above: + +```shell +pytest -v -n auto -S +``` + +[Smoke testing](https://modflow-devtools.readthedocs.io/en/latest/md/markers.html#smoke-testing) is a form of integration testing which aims to test a decent fraction of the codebase quickly enough to run often during development. + +#### External model tests + +Tests using models from external repositories can be selected with the `repo` marker: + +```shell +pytest -v -n auto -m "repo" +``` -External model tests are located in their own files: +The `large` marker is a subset of the `repo` marker. To test models excluded from commit-triggered CI and only run on GitHub Actions nightly: ```shell -# Run MODFLOW 6 test models +pytest -v -n auto -m "large" +``` + +Test scripts for external model repositories can also be run independently: + +```shell +# MODFLOW 6 test models pytest -v -n auto test_z01_testmodels_mf6.py -# Run MODFLOW 5 to 6 conversion test models +# MODFLOW 5 to 6 conversion test models pytest -v -n auto test_z02_testmodels_mf5to6.py -# Run example models +# models from modflow6-examples repo pytest -v -n auto test_z03_examples.py -# Run large test models +# models from modflow6-largetestmodels repo pytest -v -n auto test_z03_largetestmodels.py ``` + +Tests load external models from fixtures provided by `modflow-devtools`. External model tests can be selected by model or simulation name, or by packages used. See the [`modflow-devtools` documentation](https://modflow-devtools.readthedocs.io/en/latest/md/fixtures.html#filtering) for usage examples. Note that filtering options only apply to tests using external models, and will not filter tests defining models in code — for that, the `pytest` built-in `-k` option may be used. + +#### Writing tests + +Tests should ideally follow a few conventions for easier maintenance: + +- Use temporary directory fixtures. Tests which write to disk should use `pytest`'s built-in `tmp_path` fixtures or one of the [keepable temporary directory fixtures from `modflow-devtools`](https://modflow-devtools.readthedocs.io/en/latest/md/fixtures.html#keepable-temporary-directories). This prevents tests from polluting one another's state. + +- Use markers for convenient (de-)selection: + - `@pytest.mark.slow` if the test doesn't complete in a few seconds (this preserves the ability to quickly [`--smoke` test](https://modflow-devtools.readthedocs.io/en/latest/md/markers.html#smoke-testing) + - `@pytest.mark.repo` if the test relies on external model repositories + - `@pytest.mark.regression` if the test compares results from different versions + +The test suite must pass before code can be merged, so be sure it passes locally before opening a PR. diff --git a/README.md b/README.md index f4e8f192285..4da440d2e02 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ This repository contains an `./autotest` folder with python scripts for building * [modflowpy/pymake](https://github.com/modflowpy/pymake) * [modflowpy/flopy](https://github.com/modflowpy/flopy) +* [MODFLOW-USGS/modflow6-examples](https://github.com/MODFLOW-USGS/modflow6-examples) * [MODFLOW-USGS/modflow6-testmodels](https://github.com/MODFLOW-USGS/modflow6-testmodels) * [MODFLOW-USGS/modflow6-largetestmodels](https://github.com/MODFLOW-USGS/modflow6-largetestmodels) * [MODFLOW-USGS/executables](https://github.com/MODFLOW-USGS/executables) diff --git a/autotest/binary_file_writer.py b/autotest/binary_file_writer.py deleted file mode 100644 index 5d8771a0424..00000000000 --- a/autotest/binary_file_writer.py +++ /dev/null @@ -1,202 +0,0 @@ -import numpy as np - - -def write_head( - fbin, - data, - kstp=1, - kper=1, - pertim=1.0, - totim=1.0, - text=" HEAD", - ilay=1, -): - dt = np.dtype( - [ - ("kstp", np.int32), - ("kper", np.int32), - ("pertim", np.float64), - ("totim", np.float64), - ("text", "S16"), - ("ncol", np.int32), - ("nrow", np.int32), - ("ilay", np.int32), - ] - ) - nrow = data.shape[0] - ncol = data.shape[1] - h = np.array((kstp, kper, pertim, totim, text, ncol, nrow, ilay), dtype=dt) - h.tofile(fbin) - data.tofile(fbin) - return - - -def write_budget( - fbin, - data, - kstp=1, - kper=1, - text=" FLOW-JA-FACE", - imeth=1, - delt=1.0, - pertim=1.0, - totim=1.0, - text1id1=" GWF-1", - text2id1=" GWF-1", - text1id2=" GWF-1", - text2id2=" NPF", -): - dt = np.dtype( - [ - ("kstp", np.int32), - ("kper", np.int32), - ("text", "S16"), - ("ndim1", np.int32), - ("ndim2", np.int32), - ("ndim3", np.int32), - ("imeth", np.int32), - ("delt", np.float64), - ("pertim", np.float64), - ("totim", np.float64), - ] - ) - - if imeth == 1: - ndim1 = data.shape[0] - ndim2 = 1 - ndim3 = -1 - h = np.array( - ( - kstp, - kper, - text, - ndim1, - ndim2, - ndim3, - imeth, - delt, - pertim, - totim, - ), - dtype=dt, - ) - h.tofile(fbin) - data.tofile(fbin) - - elif imeth == 6: - ndim1 = 1 - ndim2 = 1 - ndim3 = -1 - h = np.array( - ( - kstp, - kper, - text, - ndim1, - ndim2, - ndim3, - imeth, - delt, - pertim, - totim, - ), - dtype=dt, - ) - h.tofile(fbin) - - # write text1id1, ... - dt = np.dtype( - [ - ("text1id1", "S16"), - ("text1id2", "S16"), - ("text2id1", "S16"), - ("text2id2", "S16"), - ] - ) - h = np.array((text1id1, text1id2, text2id1, text2id2), dtype=dt) - h.tofile(fbin) - - # write ndat (number of floating point columns) - colnames = data.dtype.names - ndat = len(colnames) - 2 - dt = np.dtype([("ndat", np.int32)]) - h = np.array([(ndat,)], dtype=dt) - h.tofile(fbin) - - # write auxiliary column names - naux = ndat - 1 - if naux > 0: - auxtxt = [f"{colname:16}" for colname in colnames[3:]] - auxtxt = tuple(auxtxt) - dt = np.dtype([(colname, "S16") for colname in colnames[3:]]) - h = np.array(auxtxt, dtype=dt) - h.tofile(fbin) - - # write nlist - nlist = data.shape[0] - dt = np.dtype([("nlist", np.int32)]) - h = np.array([(nlist,)], dtype=dt) - h.tofile(fbin) - - # write the data - data.tofile(fbin) - - pass - else: - raise Exception(f"unknown method code {imeth}") - return - - -def uniform_flow_field(qx, qy, qz, shape, delr=None, delc=None, delv=None): - - nlay, nrow, ncol = shape - - # create spdis array for the uniform flow field - dt = np.dtype( - [ - ("ID1", np.int32), - ("ID2", np.int32), - ("FLOW", np.float64), - ("QX", np.float64), - ("QY", np.float64), - ("QZ", np.float64), - ] - ) - spdis = np.array( - [(id1, id1, 0.0, qx, qy, qz) for id1 in range(nlay * nrow * ncol)], - dtype=dt, - ) - - # create the flowja array for the uniform flow field (assume top-bot = 1) - flowja = [] - if delr is None: - delr = 1.0 - if delc is None: - delc = 1.0 - if delv is None: - delv = 1.0 - for k in range(nlay): - for i in range(nrow): - for j in range(ncol): - # diagonal - flowja.append(0.0) - # up - if k > 0: - flowja.append(-qz * delr * delc) - # back - if i > 0: - flowja.append(-qy * delr * delv) - # left - if j > 0: - flowja.append(qx * delc * delv) - # right - if j < ncol - 1: - flowja.append(-qx * delc * delv) - # front - if i < nrow - 1: - flowja.append(qy * delr * delv) - # bottom - if k < nlay - 1: - flowja.append(qz * delr * delc) - flowja = np.array(flowja, dtype=np.float64) - return spdis, flowja diff --git a/autotest/budget_file_compare.py b/autotest/budget_file_compare.py deleted file mode 100644 index cd69f2ccdac..00000000000 --- a/autotest/budget_file_compare.py +++ /dev/null @@ -1,120 +0,0 @@ -# utility for comparing two MODFLOW 6 budget files - -# To use this eval_bud_diff function on a gwf or gwt budget file, -# the function may need ia, in order to exclude comparison of the residual -# term, which is stored in the diagonal position of the flowja array. -# The following code can be used to extract ia from the grb file. -# get ia/ja from binary grid file -# fname = '{}.dis.grb'.format(os.path.basename(sim.name)) -# fpth = os.path.join(sim.simpath, fname) -# grbobj = flopy.mf6.utils.MfGrdFile(fpth) -# ia = grbobj._datadict['IA'] - 1 - - -import os - -import numpy as np - - -def eval_bud_diff(fpth, b0, b1, ia=None, dtol=1e-6): - diffmax = 0.0 - difftag = "None" - difftime = None - fail = False - - # build list of cbc data to retrieve - avail = b0.get_unique_record_names() - - # initialize list for storing totals for each budget term terms - cbc_keys = [] - for t in avail: - if isinstance(t, bytes): - t = t.decode() - t = t.strip() - cbc_keys.append(t) - - # open a summary file and write header - f = open(fpth, "w") - line = f"{'Time':15s}" - line += f" {'Datatype':15s}" - line += f" {'File 1':15s}" - line += f" {'File 2':15s}" - line += f" {'Difference':15s}" - f.write(line + "\n") - f.write(len(line) * "-" + "\n") - - # get data from cbc file - kk = b0.get_kstpkper() - times = b0.get_times() - for idx, (k, t) in enumerate(zip(kk, times)): - v0sum = 0.0 - v1sum = 0.0 - for key in cbc_keys: - v0 = b0.get_data(kstpkper=k, text=key)[0] - v1 = b1.get_data(kstpkper=k, text=key)[0] - if isinstance(v0, np.recarray): - v0 = v0["q"].sum() - v1 = v1["q"].sum() - else: - v0 = v0.flatten() - v1 = v1.flatten() - if key == "FLOW-JA-FACE": - # Set residual (stored in diagonal of flowja) to zero - if ia is None: - raise Exception("ia is required for model flowja") - idiagidx = ia[:-1] - v0[idiagidx] = 0.0 - v1[idiagidx] = 0.0 - v0 = v0.sum() - v1 = v1.sum() - - # sum all of the values - if key != "AUXILIARY": - v0sum += v0 - v1sum += v1 - - diff = v0 - v1 - if abs(diff) > abs(diffmax): - diffmax = diff - difftag = key - difftime = t - if abs(diff) > dtol: - fail = True - line = f"{t:15g}" - line += f" {key:15s}" - line += f" {v0:15g}" - line += f" {v1:15g}" - line += f" {diff:15g}" - f.write(line + "\n") - - # evaluate the sums - diff = v0sum - v1sum - if abs(diff) > dtol: - fail = True - line = f"{t:15g}" - line += f" {'TOTAL':15s}" - line += f" {v0sum:15g}" - line += f" {v1sum:15g}" - line += f" {diff:15g}" - f.write(line + "\n") - - msg = f"\nSummary of changes in {os.path.basename(fpth)}\n" - msg += "-" * 72 + "\n" - msg += f"Maximum cbc difference: {diffmax}\n" - msg += f"Maximum cbc difference time: {difftime}\n" - msg += f"Maximum cbc datatype: {difftag}\n" - if fail: - msg += f"Maximum cbc criteria exceeded: {dtol}" - assert not fail, msg - - # close summary file and print the final message - f.close() - print(msg) - - msg = f"sum of first cbc file flows ({v0sum}) " + f"exceeds dtol ({dtol})" - assert abs(v0sum) < dtol, msg - - msg = f"sum of second cbc file flows ({v1sum}) " + f"exceeds dtol ({dtol})" - assert abs(v1sum) < dtol, msg - - return diff --git a/autotest/build_exes.py b/autotest/build_exes.py index 3d71b8da338..f63c0401689 100644 --- a/autotest/build_exes.py +++ b/autotest/build_exes.py @@ -2,10 +2,8 @@ from pathlib import Path import pytest -from modflow_devtools.build import meson_build - from conftest import project_root_path - +from modflow_devtools.build import meson_build repository = "MODFLOW-USGS/modflow6" top_bin_path = project_root_path / "bin" @@ -20,12 +18,16 @@ def test_meson_build(bin_path): meson_build( project_path=project_root_path, build_path=project_root_path / "builddir", - bin_path=bin_path + bin_path=bin_path, ) if __name__ == "__main__": - parser = argparse.ArgumentParser("Rebuild local development version of MODFLOW 6") - parser.add_argument("-p", "--path", help="path to bin directory", default=top_bin_path) + parser = argparse.ArgumentParser( + "Rebuild local development version of MODFLOW 6" + ) + parser.add_argument( + "-p", "--path", help="path to bin directory", default=top_bin_path + ) args = parser.parse_args() test_meson_build(Path(args.path).resolve()) diff --git a/autotest/scripts/cross_section_functions.py b/autotest/cross_section_functions.py similarity index 100% rename from autotest/scripts/cross_section_functions.py rename to autotest/cross_section_functions.py diff --git a/autotest/disu_util.py b/autotest/disu_util.py deleted file mode 100644 index 041e728622b..00000000000 --- a/autotest/disu_util.py +++ /dev/null @@ -1,101 +0,0 @@ -import numpy as np - - -def get_disu_kwargs(nlay, nrow, ncol, delr, delc, tp, botm): - """ - Simple utility for creating args needed to construct - a disu package - - """ - - def get_nn(k, i, j): - return k * nrow * ncol + i * ncol + j - - nodes = nlay * nrow * ncol - iac = np.zeros((nodes), dtype=int) - ja = [] - area = np.zeros((nodes), dtype=float) - top = np.zeros((nodes), dtype=float) - bot = np.zeros((nodes), dtype=float) - ihc = [] - cl12 = [] - hwva = [] - for k in range(nlay): - for i in range(nrow): - for j in range(ncol): - # diagonal - n = get_nn(k, i, j) - ja.append(n) - iac[n] += 1 - area[n] = delr[i] * delc[j] - ihc.append(n + 1) - cl12.append(n + 1) - hwva.append(n + 1) - if k == 0: - top[n] = tp - else: - top[n] = botm[k - 1] - bot[n] = botm[k] - # up - if k > 0: - ja.append(get_nn(k - 1, i, j)) - iac[n] += 1 - ihc.append(0) - dz = botm[k - 1] - botm[k] - cl12.append(0.5 * dz) - hwva.append(delr[i] * delc[j]) - # back - if i > 0: - ja.append(get_nn(k, i - 1, j)) - iac[n] += 1 - ihc.append(1) - cl12.append(0.5 * delc[i]) - hwva.append(delr[j]) - # left - if j > 0: - ja.append(get_nn(k, i, j - 1)) - iac[n] += 1 - ihc.append(1) - cl12.append(0.5 * delr[j]) - hwva.append(delc[i]) - # right - if j < ncol - 1: - ja.append(get_nn(k, i, j + 1)) - iac[n] += 1 - ihc.append(1) - cl12.append(0.5 * delr[j]) - hwva.append(delc[i]) - # front - if i < nrow - 1: - ja.append(get_nn(k, i + 1, j)) - iac[n] += 1 - ihc.append(1) - cl12.append(0.5 * delc[i]) - hwva.append(delr[j]) - # bottom - if k < nlay - 1: - ja.append(get_nn(k + 1, i, j)) - iac[n] += 1 - ihc.append(0) - if k == 0: - dz = tp - botm[k] - else: - dz = botm[k - 1] - botm[k] - cl12.append(0.5 * dz) - hwva.append(delr[i] * delc[j]) - ja = np.array(ja, dtype=int) - nja = ja.shape[0] - hwva = np.array(hwva, dtype=float) - kw = {} - kw["nodes"] = nodes - kw["nja"] = nja - kw["nvert"] = None - kw["top"] = top - kw["bot"] = bot - kw["area"] = area - kw["iac"] = iac - kw["ja"] = ja - kw["ihc"] = ihc - kw["cl12"] = cl12 - kw["hwva"] = hwva - return kw diff --git a/autotest/framework.py b/autotest/framework.py index c37bced6250..6e4e89c0832 100644 --- a/autotest/framework.py +++ b/autotest/framework.py @@ -1,40 +1,11 @@ -import os -import sys +import flopy -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) +class TestFramework: + # tell pytest this isn't a test class, don't collect it + __test__ = False - -def running_on_CI(): - return "TRAVIS" in os.environ or "CI" in os.environ - - -def set_teardown_test(): - teardown = True - for idx, arg in enumerate(sys.argv): - if arg.lower() == "--keep": - teardown = False - return teardown - - -class testing_framework(object): - def __init__(self): - return - - def build_mf6_models(self, build_function, idx, exdir): + def build(self, build_function, idx, exdir): """ Build base and regression MODFLOW 6 models @@ -58,28 +29,7 @@ def build_mf6_models(self, build_function, idx, exdir): else: regression.write_input() - def build_mf6_models_legacy(self, build_function, idx, exdir): - """ - Build base and regression for older MODFLOW 6 models - - Parameters - ---------- - build_function : function - user defined function that builds a base model and optionally - builds a regression model. If a regression model is not built - then None must be returned from the function for the regression - model. - idx : int - counter that corresponds to exdir entry - exdir : str - path to regression model files - """ - base, regression = build_function(idx, exdir) - base.write_simulation() - if regression is not None: - regression.write_input() - - def run_mf6(self, sim): + def run(self, sim, workspace=None): """ Run the MODFLOW 6 simulation and compare to existing head file or appropriate MODFLOW-2005, MODFLOW-NWT, MODFLOW-USG, or MODFLOW-LGR run. @@ -90,11 +40,14 @@ def run_mf6(self, sim): MODFLOW 6 autotest simulation object that runs the base and regression models, compares the results, and tears down the test if successful. + workspace : str + The path to the workspace where the test is run. """ - print(os.getcwd()) - sim.set_model(sim.name, testModel=False) + + sim.set_model( + sim.name if workspace is None else workspace, testModel=False + ) sim.run() sim.compare() if sim.exfunc is not None: sim.exfunc(sim) - sim.teardown() diff --git a/autotest/get_exes.py b/autotest/get_exes.py index 4b2d31c870e..0a95dbd3fe2 100644 --- a/autotest/get_exes.py +++ b/autotest/get_exes.py @@ -5,13 +5,12 @@ import flopy import pytest +from conftest import project_root_path from flaky import flaky from modflow_devtools.build import meson_build from modflow_devtools.download import download_and_unzip, get_release from modflow_devtools.misc import get_ostag -from conftest import project_root_path - repository = "MODFLOW-USGS/modflow6" top_bin_path = project_root_path / "bin" @@ -22,7 +21,7 @@ def get_asset_name(asset: dict) -> str: if "win" in ostag: return name else: - prefix = name.rpartition('_')[0] + prefix = name.rpartition("_")[0] prefix += f"_{ostag}" return f"{prefix}.zip" @@ -43,9 +42,13 @@ def test_rebuild_release(rebuilt_bin_path: Path): release = get_release(repository) assets = release["assets"] ostag = get_ostag() - asset = next(iter([a for a in assets if a["name"] == get_asset_name(a)]), None) + asset = next( + iter([a for a in assets if a["name"] == get_asset_name(a)]), None + ) if not asset: - warn(f"Couldn't find asset for OS {get_ostag()}, available assets:\n{assets}") + warn( + f"Couldn't find asset for OS {get_ostag()}, available assets:\n{assets}" + ) with TemporaryDirectory() as td: download_path = Path(td) @@ -56,7 +59,9 @@ def test_rebuild_release(rebuilt_bin_path: Path): ) # update IDEVELOPMODE - source_files_path = download_path / asset["name"].replace(".zip", "") / "src" + source_files_path = ( + download_path / asset["name"].replace(".zip", "") / "src" + ) version_file_path = source_files_path / "Utilities" / "version.f90" with open(version_file_path) as f: lines = f.read().splitlines() @@ -72,7 +77,7 @@ def test_rebuild_release(rebuilt_bin_path: Path): meson_build( project_path=source_files_path.parent, build_path=download_path / "builddir", - bin_path=rebuilt_bin_path + bin_path=rebuilt_bin_path, ) @@ -84,7 +89,9 @@ def test_get_executables(downloaded_bin_path: Path): if __name__ == "__main__": - parser = argparse.ArgumentParser("Get executables needed for MODFLOW 6 testing") + parser = argparse.ArgumentParser( + "Get executables needed for MODFLOW 6 testing" + ) parser.add_argument("-p", "--path", help="path to top-level bin directory") args = parser.parse_args() bin_path = Path(args.path).resolve() if args.path else top_bin_path diff --git a/autotest/pyproject.toml b/autotest/pyproject.toml index dbb4477760a..a3bce3133ee 100644 --- a/autotest/pyproject.toml +++ b/autotest/pyproject.toml @@ -5,4 +5,4 @@ build-backend = "setuptools.build_meta" [tool.black] line-length = 79 -target_version = ["py37"] +target_version = ["py37"] \ No newline at end of file diff --git a/autotest/pytest.ini b/autotest/pytest.ini index be844af8904..013c63a54ff 100644 --- a/autotest/pytest.ini +++ b/autotest/pytest.ini @@ -1,7 +1,16 @@ [pytest] +python_files = + test_*.py + *_test*.py markers = slow: tests taking more than a few seconds to complete repo: tests using models loaded from an external repository large: tests using large models (examples and largetestmodels) regression: tests comparing results from different versions - developmode: tests that should only run with IDEVELOPMODE = 1 \ No newline at end of file + developmode: tests that should only run with IDEVELOPMODE = 1 + gwf: tests for groundwater flow models + gwt: tests for groundwater transport models + ats: tests for adaptive time step package + aux: tests for auxiliary variables + lak: tests for lake package + maw: tests for multi-aquifer well package diff --git a/autotest/simulation.py b/autotest/simulation.py index a354d5873c3..47a45aa0799 100644 --- a/autotest/simulation.py +++ b/autotest/simulation.py @@ -2,14 +2,14 @@ import shutil import sys import time +from traceback import format_exc -import numpy as np import flopy +import numpy as np +from common_regression import (get_mf6_comparison, get_mf6_files, + get_namefiles, setup_mf6, setup_mf6_comparison) from flopy.utils.compare import compare_heads - -from common_regression import get_namefiles, get_mf6_files, setup_mf6, setup_mf6_comparison, get_mf6_comparison -from framework import running_on_CI, set_teardown_test -import targets +from modflow_devtools.misc import is_in_ci sfmt = "{:25s} - {}" extdict = { @@ -21,7 +21,10 @@ } -class Simulation(object): +class TestSimulation: + # tell pytest this isn't a test class, don't collect it + __test__ = False + def __init__( self, name, @@ -38,41 +41,12 @@ def __init__( make_comparison=True, simpath=None, ): - teardown_test = set_teardown_test() - for idx, arg in enumerate(sys.argv): - if arg[2:].lower() in list(targets.target_dict.keys()): - key = arg[2:].lower() - exe0 = targets.target_dict[key] - exe = os.path.join(os.path.dirname(exe0), sys.argv[idx + 1]) - msg = ( - f"replacing {key} executable " - + f'"{targets.target_dict[key]}" with ' - + f'"{exe}".' - ) - print(msg) - targets.target_dict[key] = exe - - if exe_dict is not None: - if not isinstance(exe_dict, dict): - msg = "exe_dict must be a dictionary" - assert False, msg - keys = list(targets.target_dict.keys()) - for key, value in exe_dict.items(): - if key in keys: - exe0 = targets.target_dict[key] - exe = os.path.join(os.path.dirname(exe0), value) - msg = ( - f"replacing {key} executable " - + f'"{targets.target_dict[key]}" with ' - + f'"{exe}".' - ) - print(msg) - targets.target_dict[key] = exe - msg = sfmt.format("Initializing test", name) print(msg) + self.name = name self.exfunc = exfunc + self.targets = exe_dict self.simpath = simpath self.inpt = None self.outp = None @@ -122,11 +96,10 @@ def __init__( # set allow failure self.require_failure = require_failure - self.teardown_test = teardown_test self.success = False # set is_ci - self.is_CI = running_on_CI() + self.is_CI = is_in_ci() return @@ -151,23 +124,18 @@ def set_model(self, pth, testModel=True): # determine comparison model self.setup_comparison(pth, pth, testModel=testModel) # if self.mf6_regression: - # self.action = "mf6-regression" + # self.action = "mf6_regression" # else: - # self.action = pymake.get_mf6_comparison(pth) + # self.action = get_mf6_comparison(pth) if self.action is not None: - if "mf6" in self.action or "mf6-regression" in self.action: + if "mf6" in self.action or "mf6_regression" in self.action: cinp, self.coutp = get_mf6_files(fpth) def setup(self, src, dst): - msg = sfmt.format("Setup test", self.name) + msg = sfmt.format("Setting up test workspace", self.name) print(msg) self.originpath = src self.simpath = dst - # write message - print( - "running pymake.setup_mf6 from " - + f"{os.path.abspath(os.getcwd())}" - ) try: self.inpt, self.outp = setup_mf6(src=src, dst=dst) print("waiting...") @@ -177,7 +145,7 @@ def setup(self, src, dst): success = False print(f"source: {src}") print(f"destination: {dst}") - assert success, "did not run pymake.setup_mf6" + assert success, f"Failed to set up test workspace: {format_exc()}" if success: self.setup_comparison(src, dst) @@ -207,15 +175,13 @@ def setup_comparison(self, src, dst, testModel=True): # Copy comparison simulations if available if self.mf6_regression: - action = "mf6-regression" + action = "mf6_regression" pth = os.path.join(dst, action) if os.path.isdir(pth): shutil.rmtree(pth) shutil.copytree(dst, pth) elif testModel: - action = setup_mf6_comparison( - src, dst, remove_existing=self.teardown_test - ) + action = setup_mf6_comparison(src, dst, remove_existing=True) else: action = get_mf6_comparison(dst) @@ -234,8 +200,7 @@ def run(self): nam = None # run mf6 models - target, ext = os.path.splitext(targets.program) - exe = os.path.abspath(targets.target_dict[target]) + exe = str(self.targets["mf6"].absolute()) msg = sfmt.format("using executable", exe) print(msg) try: @@ -294,13 +259,13 @@ def run(self): else: cpth = os.path.join(self.simpath, self.action) key = self.action.lower().replace(".cmp", "") - exe = os.path.abspath(targets.target_dict[key]) + exe = str(self.targets[key].absolute()) msg = sfmt.format("comparison executable", exe) print(msg) if ( "mf6" in key or "libmf6" in key - or "mf6-regression" in key + or "mf6_regression" in key ): nam = None else: @@ -376,7 +341,7 @@ def compare(self): "ahd", "bin", ) - if "mf6-regression" in self.action: + if "mf6_regression" in self.action: success, msgall = self._compare_heads( msgall, extensions=head_extensions, @@ -486,13 +451,13 @@ def compare(self): msgall += msg + " ... FAILED\n" # compare concentrations - if "mf6-regression" in self.action: + if "mf6_regression" in self.action: success, msgall = self._compare_concentrations(msgall) if not success: self.success = False # compare cbc files - if "mf6-regression" in self.action: + if "mf6_regression" in self.action: cbc_extensions = ( "cbc", "bud", @@ -506,31 +471,6 @@ def compare(self): assert self.success, msgall return - def teardown(self): - """ - Remove the example folder - - """ - if self.success: - if self.teardown_test: - msg = sfmt.format("Teardown test", self.name) - print(msg) - - # wait to delete on windows - if sys.platform.lower() == "win32": - time.sleep(3) - - try: - shutil.rmtree(self.simpath) - success = True - except: - print("Could not remove test " + self.name) - success = False - assert success - else: - print("Retaining test files") - return - def _get_mfsim_listing(self, lst_pth): """Get the tail of the mfsim.lst listing file""" msg = "" @@ -605,7 +545,7 @@ def _regression_files(self, extensions): if file_name.lower().endswith(extension): files0.append(fpth0) fpth1 = os.path.join( - self.simpath, "mf6-regression", file_name + self.simpath, "mf6_regression", file_name ) files1.append(fpth1) break diff --git a/autotest/targets.py b/autotest/targets.py deleted file mode 100644 index 9202f39a3bf..00000000000 --- a/autotest/targets.py +++ /dev/null @@ -1,98 +0,0 @@ -import os -import subprocess -import sys - -import flopy - - -def target_pth(target, pth): - exe_exists = flopy.which(target, path=pth) - # if target does not exist in specified path determine if it - # exists anywhere in the path - if exe_exists is None: - exe_exists = flopy.which(target) - if exe_exists is None: - exe_exists = os.path.abspath(os.path.join(pth, target)) - raise Exception(f"{exe_exists} does not exist or is not executable.") - return os.path.abspath(exe_exists) - - -target_ext = "" -target_so = ".so" -sysinfo = sys.platform.lower() -if sysinfo.lower() == "win32": - target_ext = ".exe" - target_so = ".dll" -elif sysinfo.lower() == "darwin": - target_so = ".dylib" - -# paths to executables for previous versions of MODFLOW -downloaded_bindir = os.path.join("..", "bin", "downloaded") -rebuilt_bindir = os.path.join("..", "bin", "rebuilt") - -# paths to MODFLOW 6 executable, source files, and example files -bindir = os.path.join("..", "bin") - -# create dictionary of valid executable targets for regression tests -target_dict = {} - -target = target_pth(f"mf2005dbl{target_ext}", downloaded_bindir) -target_dict["mf2005"] = target -target = target_pth(f"mfnwtdbl{target_ext}", downloaded_bindir) -target_dict["mfnwt"] = target -target = target_pth(f"mfusgdbl{target_ext}", downloaded_bindir) -target_dict["mfusg"] = target -target = target_pth(f"mflgrdbl{target_ext}", downloaded_bindir) -target_dict["mflgr"] = target -target = target_pth(f"mf2005{target_ext}", downloaded_bindir) -target_dict["mf2005s"] = target -target = target_pth(f"mt3dms{target_ext}", downloaded_bindir) -target_dict["mt3dms"] = target -target = target_pth(f"mf6{target_ext}", rebuilt_bindir) -target_dict["mf6-regression"] = target - -# create MODFLOW 6 target name and add to dictionary -program = f"mf6{target_ext}" -target = os.path.join(bindir, program) -target_dict["mf6"] = target - -# create MODFLOW 6 so/dll target name -tprog = f"libmf6{target_so}" -ttarg = os.path.join(bindir, tprog) -target_dict["libmf6"] = ttarg - -# add MODFLOW 5 to 6 converter to dictionary of valid executable targets -tprog = f"mf5to6{target_ext}" -ttarg = os.path.join(bindir, tprog) -target_dict["mf5to6"] = ttarg - -# add Zonebudget for 6 to dictionary of valid executable targets -tprog = f"zbud6{target_ext}" -ttarg = os.path.join(bindir, tprog) -target_dict["zbud6"] = ttarg - - -def run_exe(argv, ws="."): - buff = [] - proc = subprocess.Popen( - argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ws - ) - result, error = proc.communicate() - if result is not None: - c = result.decode("utf-8") - c = c.rstrip("\r\n") - print(f"{c}") - buff.append(c) - - return proc.returncode, buff - - -def get_mf6_version(version="mf6"): - """Function to get MODFLOW 6 version number""" - exe = target_dict[version] - return_code, buff = run_exe((exe, "-v")) - if return_code == 0: - version = buff[0].split()[1] - else: - version = None - return version diff --git a/autotest/test_cli.py b/autotest/test_cli.py index a8e8f02aca6..366963df3f3 100644 --- a/autotest/test_cli.py +++ b/autotest/test_cli.py @@ -1,19 +1,23 @@ import subprocess -from pathlib import Path -_project_root_path = Path(__file__).parent.parent -_bin_path = _project_root_path / "bin" +from conftest import project_root_path + +bin_path = project_root_path / "bin" def test_cli_version(): - output = ' '.join(subprocess.check_output([str(_bin_path / 'mf6'), "-v"]).decode().split()) + output = " ".join( + subprocess.check_output([str(bin_path / "mf6"), "-v"]).decode().split() + ) assert output.startswith("mf6:") assert output.lower().count("release") == 1 # assert output.lower().count("candidate") <= 1 print(output) - version = output.lower().rpartition(":")[2].rpartition("release")[0].strip() + version = ( + output.lower().rpartition(":")[2].rpartition("release")[0].strip() + ) v_split = version.split(".") assert len(v_split) == 3 assert all(s.isdigit() for s in v_split) diff --git a/autotest/test_gwf.py b/autotest/test_gwf.py new file mode 100644 index 00000000000..59e0d18f6ac --- /dev/null +++ b/autotest/test_gwf.py @@ -0,0 +1,27 @@ +from modflow_devtools.executables import Executables +from pytest_cases import parametrize_with_cases +from simulation import TestSimulation +from test_gwf_maw04 import GwfMaw04Cases +from test_gwf_maw_cases import GwfMawCases + + +@parametrize_with_cases("case", cases=[GwfMawCases, GwfMaw04Cases]) +def test_gwf_models(case, targets: Executables): + data, sim, cmp, exfunc = case + sim.write_simulation() + if cmp: + cmp.write_simulation() + + test = TestSimulation( + name=data.name, + exe_dict=targets, + exfunc=exfunc, + idxsim=0, # TODO: remove parameter from TestSimulation + mf6_regression=True, + require_failure=data.xfail, + make_comparison=data.compare, + ) + + test.set_model(sim.simulation_data.mfpath.get_sim_path(), testModel=False) + test.run() + test.compare() diff --git a/autotest/test_gwf_ats01.py b/autotest/test_gwf_ats01.py index be62b72fdea..167ce57ba35 100644 --- a/autotest/test_gwf_ats01.py +++ b/autotest/test_gwf_ats01.py @@ -5,33 +5,13 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwf_ats01a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" nlay, nrow, ncol = 1, 1, 2 # set dt0, dtmin, dtmax, dtadj, dtfailadj @@ -198,11 +178,8 @@ def build_model(idx, dir): def eval_flow(sim): print("evaluating flow...") - name = ex[sim.idxsim] - gwfname = name - # This will fail if budget numbers cannot be read - fpth = os.path.join(sim.simpath, f"{gwfname}.lst") + fpth = os.path.join(sim.simpath, f"{sim.name}.lst") mflist = flopy.utils.Mf6ListBudget(fpth) names = mflist.get_record_names() inc = mflist.get_incremental() @@ -212,7 +189,7 @@ def eval_flow(sim): assert v == 10.0, f"Last time should be 10. Found {v}" # ensure obs results changing monotonically - fpth = os.path.join(sim.simpath, gwfname + ".obs.csv") + fpth = os.path.join(sim.simpath, sim.name + ".obs.csv") try: tc = np.genfromtxt(fpth, names=True, delimiter=",") except: @@ -226,39 +203,19 @@ def eval_flow(sim): assert np.all(np.diff(v) < 0), msg v = tc["time"][-1] assert v == 10.0, f"Last time should be 10. Found {v}" - return -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_flow, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_flow, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + workspace = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, workspace) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_flow, idxsim=0 + ), + workspace, + ) diff --git a/autotest/test_gwf_ats02.py b/autotest/test_gwf_ats02.py index eea0c7c2fdd..7b41db9cfdc 100644 --- a/autotest/test_gwf_ats02.py +++ b/autotest/test_gwf_ats02.py @@ -6,33 +6,13 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwf_ats02a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" nlay, nrow, ncol = 5, 1, 1 botm = [80.0, 60.0, 40.0, 20.0, 0.0] @@ -194,11 +174,9 @@ def build_model(idx, dir): def make_plot(sim): print("making plots...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] - gwfname = name + ws = sim.simpath - fname = gwfname + ".hds" + fname = sim.name + ".hds" fname = os.path.join(ws, fname) hobj = flopy.utils.HeadFile(fname, precision="double") head = hobj.get_alldata()[:, :, 0, 0] @@ -231,14 +209,8 @@ def make_plot(sim): def eval_flow(sim): print("evaluating flow...") - name = ex[sim.idxsim] - gwfname = name - - if False: - make_plot(sim) - # This will fail if budget numbers cannot be read - fpth = os.path.join(sim.simpath, f"{gwfname}.lst") + fpth = os.path.join(sim.simpath, f"{sim.name}.lst") mflist = flopy.utils.Mf6ListBudget(fpth) names = mflist.get_record_names() inc = mflist.get_incremental() @@ -248,7 +220,7 @@ def eval_flow(sim): assert v == 20.0, f"Last time should be 20. Found {v}" # ensure obs results changing monotonically - fpth = os.path.join(sim.simpath, gwfname + ".obs.csv") + fpth = os.path.join(sim.simpath, sim.name + ".obs.csv") try: tc = np.genfromtxt(fpth, names=True, delimiter=",") except: @@ -259,38 +231,16 @@ def eval_flow(sim): ), "layer 1 should be dry for this period" -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_flow, idxsim=idx)) - - return - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_flow, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, 0, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_flow, idxsim=0 + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_ats03.py b/autotest/test_gwf_ats03.py index 8c4ee64715f..b36908ef866 100644 --- a/autotest/test_gwf_ats03.py +++ b/autotest/test_gwf_ats03.py @@ -12,33 +12,13 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwf_ats03a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" nlay, nrow, ncol = 1, 1, 10 @@ -214,11 +194,8 @@ def build_model(idx, dir): def eval_flow(sim): print("evaluating flow...") - name = ex[sim.idxsim] - gwfname = name - # ensure obs2 (a constant head time series) drops linearly from 100 to 50 - fpth = os.path.join(sim.simpath, gwfname + ".obs.csv") + fpth = os.path.join(sim.simpath, sim.name + ".obs.csv") try: tc = np.genfromtxt(fpth, names=True, delimiter=",") except: @@ -230,36 +207,16 @@ def eval_flow(sim): assert np.allclose(answer, result), msg -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_flow, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_flow, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, 0, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_flow, idxsim=0 + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_ats_lak01.py b/autotest/test_gwf_ats_lak01.py index f362b79a298..5f2381c08f3 100644 --- a/autotest/test_gwf_ats_lak01.py +++ b/autotest/test_gwf_ats_lak01.py @@ -3,28 +3,14 @@ # a smaller time step. import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwf_ats_lak_01a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - -# store global gwf for subsequent plotting gwf = None @@ -236,9 +222,6 @@ def build_model(idx, dir): def make_plot_xsect(sim, headall, stageall): print("making plots...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] - import matplotlib.patches as patches import matplotlib.pyplot as plt from matplotlib.collections import PatchCollection @@ -274,18 +257,13 @@ def make_plot_xsect(sim, headall, stageall): # ax.set_ylim(-10, 5) fname = "fig-xsect.pdf" - fname = os.path.join(ws, fname) + fname = os.path.join(sim.simpath, fname) plt.savefig(fname, bbox_inches="tight") - return - def make_plot(sim, times, headall, stageall): print("making plots...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] - import matplotlib.pyplot as plt fig = plt.figure(figsize=(6, 4)) @@ -296,11 +274,9 @@ def make_plot(sim, times, headall, stageall): ax.plot(times, h, "bo-", label="max head") fname = "fig-timeseries.pdf" - fname = os.path.join(ws, fname) + fname = os.path.join(sim.simpath, fname) plt.savefig(fname, bbox_inches="tight") - return - def get_kij_from_node(node, nrow, ncol): "return zero based k, i, j from zero based node number" @@ -316,16 +292,14 @@ def eval_results(sim): print("evaluating results...") # calculate volume of water and make sure it is conserved - name = ex[sim.idxsim] - gwfname = name - fname = gwfname + ".lak.bin" + fname = sim.name + ".lak.bin" fname = os.path.join(sim.simpath, fname) assert os.path.isfile(fname) bobj = flopy.utils.HeadFile(fname, text="STAGE") times = bobj.get_times() stage = bobj.get_alldata() - fname = gwfname + ".cbc" + fname = sim.name + ".cbc" fname = os.path.join(sim.simpath, fname) bobj = flopy.utils.CellBudgetFile(fname, precision="double", verbose=False) times = bobj.get_times() @@ -369,7 +343,7 @@ def eval_results(sim): print(msg) assert all_passed, "found recharge applied to cell beneath active lake" - fname = gwfname + ".hds" + fname = sim.name + ".hds" fname = os.path.join(sim.simpath, fname) assert os.path.isfile(fname) hobj = flopy.utils.HeadFile(fname) @@ -431,43 +405,21 @@ def eval_results(sim): errmsg = "lake stage does not match known answer" assert np.allclose(stage_answer, stage.flatten()), errmsg - if False: - make_plot(sim, times, head, stage) - make_plot_xsect(sim, head, stage) + # make_plot(sim, times, head, stage) + # make_plot_xsect(sim, head, stage) - return - -# - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, 0, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=0 + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_auxvars.py b/autotest/test_gwf_auxvars.py index 8a7704586a7..f19c2fb8dfe 100644 --- a/autotest/test_gwf_auxvars.py +++ b/autotest/test_gwf_auxvars.py @@ -1,32 +1,13 @@ import os import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["aux01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) auxvar1 = 101.0 auxvar2 = 102.0 @@ -317,39 +298,17 @@ def eval_model(sim): assert np.allclose(r["AUX1"], auxvar1) assert np.allclose(r["AUX2"], auxvar2) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=idx + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_auxvars02.py b/autotest/test_gwf_auxvars02.py index 80a38bc6fa3..c9ef34ee4d5 100644 --- a/autotest/test_gwf_auxvars02.py +++ b/autotest/test_gwf_auxvars02.py @@ -1,32 +1,13 @@ import os import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["aux02"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -138,39 +119,17 @@ def eval_model(sim): aname = f"AUX{a}" assert np.allclose(r[aname], a) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=idx + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_boundname01.py b/autotest/test_gwf_boundname01.py index d53c5852ce5..8a5ac6050cb 100644 --- a/autotest/test_gwf_boundname01.py +++ b/autotest/test_gwf_boundname01.py @@ -1,34 +1,14 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = [ "bndname01", ] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, exdir): @@ -176,71 +156,28 @@ def replace_quotes(idx, exdir): def eval_obs(sim): - idx = sim.idxsim - ws = exdirs[idx] - name = ex[idx] - print("evaluating observations results..." f"({name})") + print("evaluating observations results..." f"({sim.name})") - fpth = os.path.join(ws, f"gwf_{name}.chd.obs.csv") + fpth = os.path.join(sim.simpath, f"gwf_{sim.name}.chd.obs.csv") obs0 = np.genfromtxt(fpth, delimiter=",", names=True) names0 = obs0.dtype.names - fpth = os.path.join(ws, "mf6", f"gwf_{name}.chd.obs.csv") + fpth = os.path.join(sim.simpath, "mf6", f"gwf_{sim.name}.chd.obs.csv") obs1 = np.genfromtxt(fpth, delimiter=",", names=True) names1 = obs1.dtype.names assert names0 == names1, "observation names are not identical" - assert np.array_equal(obs0, obs1), "observations are not identical" - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # replace quotes - replace_quotes(idx, exdir) - - # run the test model - test.run_mf6( - Simulation( - exdir, - idxsim=idx, - ) +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, 0, str(function_tmpdir)) + test.run( + TestSimulation(name=name, exe_dict=targets, idxsim=0), + str(function_tmpdir), ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build and run the test model - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - sim = Simulation( - exdir, - idxsim=idx, - exfunc=eval_obs, - ) - replace_quotes(idx, exdir) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_buy_lak01.py b/autotest/test_gwf_buy_lak01.py index 0b9a7a8c668..7a12bb2cffa 100644 --- a/autotest/test_gwf_buy_lak01.py +++ b/autotest/test_gwf_buy_lak01.py @@ -10,28 +10,16 @@ # 3. Buoyancy package with lake and aquifer density = 1024.5 import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["buy_lak_01a"] # , 'buy_lak_01b', 'buy_lak_01c'] buy_on_list = [False] # , True, True] concbuylist = [0.0] # , 0., 35.] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -224,8 +212,7 @@ def eval_results(sim): print("evaluating results...") # calculate volume of water and make sure it is conserved - name = ex[sim.idxsim] - gwfname = "gwf_" + name + gwfname = "gwf_" + sim.name fname = gwfname + ".lak.bin" fname = os.path.join(sim.simpath, fname) assert os.path.isfile(fname) @@ -265,36 +252,16 @@ def eval_results(sim): # assert False -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, 0, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=0 + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_buy_lak02.py b/autotest/test_gwf_buy_lak02.py index 86a8a094e64..514f3348da5 100644 --- a/autotest/test_gwf_buy_lak02.py +++ b/autotest/test_gwf_buy_lak02.py @@ -1,228 +1,90 @@ -# Test the buoyancy package and the variable density flows between the lake -# and the gwf model. This model has 4 layers and a lake incised within it. -# The model is transient and has heads in the aquifer higher than the initial -# stage in the lake. As the model runs, the lake and aquifer equalize and -# should end up at the same level. The test ensures that the initial and -# final water volumes in the entire system are the same. This test is different -# from the previous test in that transport is active. There are four -# different cases: -# 1. lak and aquifer have concentration of 0. -# 2. lak and aquifer have concentration of 35. -# 3. lak has concentration of 0., aquifer is 35. -# 4. lak has concentration of 35., aquifer is 0. - import os -import sys +from typing import NamedTuple +import flopy import numpy as np -import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -ex = ["buy_lak_02a", "buy_lak_02b", "buy_lak_02c", "buy_lak_02d"] -gwt_conc_list = [0.0, 35.0, 35.0, 0.0] -lak_conc_list = [0.0, 35.0, 0.0, 35.0] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - - -def build_model(idx, dir): - lx = 7.0 - lz = 4.0 - nlay = 4 - nrow = 1 - ncol = 7 - nper = 1 - delc = 1.0 - delr = lx / ncol - delz = lz / nlay - top = 4.0 - botm = [3.0, 2.0, 1.0, 0.0] - - perlen = [50.0] - nstp = [50] - tsmult = [1.0] - - Kh = 1.0 - Kv = 1.0 - - tdis_rc = [] - for i in range(nper): - tdis_rc.append((perlen[i], nstp[i], tsmult[i])) - - nouter, ninner = 700, 300 - hclose, rclose, relax = 1e-8, 1e-6, 0.97 - - name = ex[idx] - - # build MODFLOW 6 files - ws = dir - sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws - ) - # create tdis package - tdis = flopy.mf6.ModflowTdis( - sim, time_units="DAYS", nper=nper, perioddata=tdis_rc - ) - - # create gwf model - gwfname = "gwf_" + name - gwtname = "gwt_" + name - - gwf = flopy.mf6.ModflowGwf(sim, modelname=gwfname, newtonoptions="NEWTON") - - imsgwf = flopy.mf6.ModflowIms( - sim, - print_option="ALL", - outer_dvclose=hclose, - outer_maximum=nouter, - under_relaxation="NONE", - inner_maximum=ninner, - inner_dvclose=hclose, - rcloserecord=f"{rclose} strict", - linear_acceleration="BICGSTAB", - scaling_method="NONE", - reordering_method="NONE", - relaxation_factor=relax, - filename=f"{gwfname}.ims", - ) - - idomain = np.full((nlay, nrow, ncol), 1) - idomain[0, 0, 1:6] = 0 - idomain[1, 0, 2:5] = 0 - idomain[2, 0, 3:4] = 0 - dis = flopy.mf6.ModflowGwfdis( - gwf, - nlay=nlay, - nrow=nrow, - ncol=ncol, - delr=delr, - delc=delc, - top=top, - botm=botm, - idomain=idomain, - ) - - # initial conditions - strt = np.zeros((nlay, nrow, ncol), dtype=float) - strt[0, 0, :] = 3.5 - strt[1, 0, :] = 3.0 - strt[1, 0, 1:6] = 2.5 - strt[2, 0, :] = 2.0 - strt[3, 0, :] = 1.0 - ic = flopy.mf6.ModflowGwfic(gwf, strt=strt) - - # node property flow - npf = flopy.mf6.ModflowGwfnpf( - gwf, - xt3doptions=False, - save_flows=True, - save_specific_discharge=True, - icelltype=1, - k=Kh, - k33=Kv, - ) - - sto = flopy.mf6.ModflowGwfsto(gwf, sy=0.3, ss=0.0, iconvert=1) - - buy_on = True - if buy_on: - pd = [(0, 0.7, 0.0, gwtname, "CONCENTRATION")] - buy = flopy.mf6.ModflowGwfbuy(gwf, denseref=1000.0, packagedata=pd) - - nlakeconn = 11 # note: number of connections for this lake - # pak_data = [lakeno, strt, nlakeconn, testauxvar, concentration, boundname] - pak_data = [(0, 2.25, nlakeconn, 0.0, 0.0)] - - connlen = delr / 2.0 - connwidth = delc - bedleak = "None" - con_data = [ - # con_data=(lakeno,iconn,(cellid),claktype,bedleak,belev,telev,connlen,connwidth ) - (0, 0, (0, 0, 0), "HORIZONTAL", bedleak, 10, 10, connlen, connwidth), - (0, 1, (1, 0, 1), "VERTICAL", bedleak, 10, 10, connlen, connwidth), - (0, 2, (1, 0, 1), "HORIZONTAL", bedleak, 10, 10, connlen, connwidth), - (0, 3, (2, 0, 2), "VERTICAL", bedleak, 10, 10, connlen, connwidth), - (0, 4, (2, 0, 2), "HORIZONTAL", bedleak, 10, 10, connlen, connwidth), - (0, 5, (3, 0, 3), "VERTICAL", bedleak, 10, 10, connlen, connwidth), - (0, 6, (2, 0, 4), "HORIZONTAL", bedleak, 10, 10, connlen, connwidth), - (0, 7, (2, 0, 4), "VERTICAL", bedleak, 10, 10, connlen, connwidth), - (0, 8, (1, 0, 5), "HORIZONTAL", bedleak, 10, 10, connlen, connwidth), - (0, 9, (1, 0, 5), "VERTICAL", bedleak, 10, 10, connlen, connwidth), - (0, 10, (0, 0, 6), "HORIZONTAL", bedleak, 10, 10, connlen, connwidth), - ] - - # period data - p_data = [ - (0, "STATUS", "ACTIVE"), - ] - - # note: for specifying lake number, use fortran indexing! - fname = f"{gwfname}.lak.obs.csv" - lak_obs = { - fname: [ - ("lakestage", "stage", 1), - ("lakevolume", "volume", 1), - ("lak1", "lak", 1, 1), - ("lak2", "lak", 1, 2), - ("lak3", "lak", 1, 3), - ("lak4", "lak", 1, 4), - ("lak5", "lak", 1, 5), - ("lak6", "lak", 1, 6), - ("lak7", "lak", 1, 7), - ("lak8", "lak", 1, 8), - ("lak9", "lak", 1, 9), - ("lak10", "lak", 1, 10), - ("lak11", "lak", 1, 11), - ], - "digits": 10, - } - - lak = flopy.mf6.modflow.ModflowGwflak( - gwf, - save_flows=True, - print_input=True, - print_flows=True, - print_stage=True, - stage_filerecord=f"{gwfname}.lak.bin", - budget_filerecord=f"{gwfname}.lak.bud", - nlakes=len(pak_data), - ntables=0, - packagedata=pak_data, - pname="LAK-1", - connectiondata=con_data, - perioddata=p_data, - observations=lak_obs, - auxiliary=["TESTAUXVAR", "CONCENTRATION"], - ) - - # output control - oc = flopy.mf6.ModflowGwfoc( - gwf, - budget_filerecord=f"{gwfname}.cbc", - head_filerecord=f"{gwfname}.hds", - headprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")], - saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], - printrecord=[("HEAD", "LAST"), ("BUDGET", "LAST")], +from framework import TestFramework +from pytest_cases import parametrize, parametrize_with_cases +from simulation import TestSimulation + + +class GwfBuyLakCases: + """ + Test the buoyancy package and the variable density flows between the lake + and the gwf model. This model has 4 layers and a lake incised within it. + The model is transient and has heads in the aquifer higher than the initial + stage in the lake. As the model runs, the lake and aquifer equalize and + should end up at the same level. The test ensures that the initial and + final water volumes in the entire system are the same. This test is different + from the previous test in that transport is active. There are four + different cases: + 1. lak and aquifer have concentration of 0. + 2. lak and aquifer have concentration of 35. + 3. lak has concentration of 0., aquifer is 35. + 4. lak has concentration of 35., aquifer is 0. + """ + + class Data(NamedTuple): + name: str + gwt_conc: float + lak_conc: float + + @parametrize( + data=[ + Data(name="a", gwt_conc=0, lak_conc=0), + Data(name="b", gwt_conc=35, lak_conc=35), + Data(name="c", gwt_conc=35, lak_conc=0), + Data(name="d", gwt_conc=0, lak_conc=35), + ] ) + def case_generator(self, data, function_tmpdir): + lx = 7.0 + lz = 4.0 + nlay = 4 + nrow = 1 + ncol = 7 + nper = 1 + delc = 1.0 + delr = lx / ncol + delz = lz / nlay + top = 4.0 + botm = [3.0, 2.0, 1.0, 0.0] + + perlen = [50.0] + nstp = [50] + tsmult = [1.0] + + Kh = 1.0 + Kv = 1.0 + + tdis_rc = [] + for i in range(nper): + tdis_rc.append((perlen[i], nstp[i], tsmult[i])) + + nouter, ninner = 700, 300 + hclose, rclose, relax = 1e-8, 1e-6, 0.97 + + # build MODFLOW 6 files + sim = flopy.mf6.MFSimulation( + sim_name=data.name, + version="mf6", + exe_name="mf6", + sim_ws=str(function_tmpdir), + ) + # create tdis package + tdis = flopy.mf6.ModflowTdis( + sim, time_units="DAYS", nper=nper, perioddata=tdis_rc + ) - # create gwt model - transport = True - if transport: + # create gwf model + gwfname = "gwf_" + data.name + gwtname = "gwt_" + data.name - gwt = flopy.mf6.ModflowGwt(sim, modelname=gwtname) + gwf = flopy.mf6.ModflowGwf( + sim, modelname=gwfname, newtonoptions="NEWTON" + ) - imsgwt = flopy.mf6.ModflowIms( + imsgwf = flopy.mf6.ModflowIms( sim, print_option="ALL", outer_dvclose=hclose, @@ -235,12 +97,15 @@ def build_model(idx, dir): scaling_method="NONE", reordering_method="NONE", relaxation_factor=relax, - filename=f"{gwtname}.ims", + filename=f"{gwfname}.ims", ) - sim.register_ims_package(imsgwt, [gwt.name]) - dis = flopy.mf6.ModflowGwtdis( - gwt, + idomain = np.full((nlay, nrow, ncol), 1) + idomain[0, 0, 1:6] = 0 + idomain[1, 0, 2:5] = 0 + idomain[2, 0, 3:4] = 0 + dis = flopy.mf6.ModflowGwfdis( + gwf, nlay=nlay, nrow=nrow, ncol=ncol, @@ -252,181 +117,363 @@ def build_model(idx, dir): ) # initial conditions - strt = gwt_conc_list[idx] - ic = flopy.mf6.ModflowGwtic(gwt, strt=strt) - - # advection - adv = flopy.mf6.ModflowGwtadv(gwt, scheme="UPSTREAM") - - # storage - porosity = 0.30 - sto = flopy.mf6.ModflowGwtmst(gwt, porosity=porosity) + strt = np.zeros((nlay, nrow, ncol), dtype=float) + strt[0, 0, :] = 3.5 + strt[1, 0, :] = 3.0 + strt[1, 0, 1:6] = 2.5 + strt[2, 0, :] = 2.0 + strt[3, 0, :] = 1.0 + ic = flopy.mf6.ModflowGwfic(gwf, strt=strt) + + # node property flow + npf = flopy.mf6.ModflowGwfnpf( + gwf, + xt3doptions=False, + save_flows=True, + save_specific_discharge=True, + icelltype=1, + k=Kh, + k33=Kv, + ) - # sources - sourcerecarray = [ - (), + sto = flopy.mf6.ModflowGwfsto(gwf, sy=0.3, ss=0.0, iconvert=1) + + buy_on = True + if buy_on: + pd = [(0, 0.7, 0.0, gwtname, "CONCENTRATION")] + buy = flopy.mf6.ModflowGwfbuy(gwf, denseref=1000.0, packagedata=pd) + + nlakeconn = 11 # note: number of connections for this lake + # pak_data = [lakeno, strt, nlakeconn, testauxvar, concentration, boundname] + pak_data = [(0, 2.25, nlakeconn, 0.0, 0.0)] + + connlen = delr / 2.0 + connwidth = delc + bedleak = "None" + con_data = [ + # con_data=(lakeno,iconn,(cellid),claktype,bedleak,belev,telev,connlen,connwidth ) + ( + 0, + 0, + (0, 0, 0), + "HORIZONTAL", + bedleak, + 10, + 10, + connlen, + connwidth, + ), + (0, 1, (1, 0, 1), "VERTICAL", bedleak, 10, 10, connlen, connwidth), + ( + 0, + 2, + (1, 0, 1), + "HORIZONTAL", + bedleak, + 10, + 10, + connlen, + connwidth, + ), + (0, 3, (2, 0, 2), "VERTICAL", bedleak, 10, 10, connlen, connwidth), + ( + 0, + 4, + (2, 0, 2), + "HORIZONTAL", + bedleak, + 10, + 10, + connlen, + connwidth, + ), + (0, 5, (3, 0, 3), "VERTICAL", bedleak, 10, 10, connlen, connwidth), + ( + 0, + 6, + (2, 0, 4), + "HORIZONTAL", + bedleak, + 10, + 10, + connlen, + connwidth, + ), + (0, 7, (2, 0, 4), "VERTICAL", bedleak, 10, 10, connlen, connwidth), + ( + 0, + 8, + (1, 0, 5), + "HORIZONTAL", + bedleak, + 10, + 10, + connlen, + connwidth, + ), + (0, 9, (1, 0, 5), "VERTICAL", bedleak, 10, 10, connlen, connwidth), + ( + 0, + 10, + (0, 0, 6), + "HORIZONTAL", + bedleak, + 10, + 10, + connlen, + connwidth, + ), ] - ssm = flopy.mf6.ModflowGwtssm(gwt, sources=sourcerecarray) - lak_conc = lak_conc_list[idx] - lktpackagedata = [ - (0, lak_conc, 99.0, 999.0, "mylake"), + # period data + p_data = [ + (0, "STATUS", "ACTIVE"), ] - lkt = flopy.mf6.modflow.ModflowGwtlkt( - gwt, - boundnames=True, + + # note: for specifying lake number, use fortran indexing! + fname = f"{gwfname}.lak.obs.csv" + lak_obs = { + fname: [ + ("lakestage", "stage", 1), + ("lakevolume", "volume", 1), + ("lak1", "lak", 1, 1), + ("lak2", "lak", 1, 2), + ("lak3", "lak", 1, 3), + ("lak4", "lak", 1, 4), + ("lak5", "lak", 1, 5), + ("lak6", "lak", 1, 6), + ("lak7", "lak", 1, 7), + ("lak8", "lak", 1, 8), + ("lak9", "lak", 1, 9), + ("lak10", "lak", 1, 10), + ("lak11", "lak", 1, 11), + ], + "digits": 10, + } + + lak = flopy.mf6.modflow.ModflowGwflak( + gwf, save_flows=True, print_input=True, print_flows=True, - print_concentration=True, - concentration_filerecord=gwtname + ".lkt.bin", - budget_filerecord="gwtlak1.bud", - packagedata=lktpackagedata, - pname="LKT-1", - flow_package_name="LAK-1", - flow_package_auxiliary_name="CONCENTRATION", - auxiliary=["aux1", "aux2"], + print_stage=True, + stage_filerecord=f"{gwfname}.lak.bin", + budget_filerecord=f"{gwfname}.lak.bud", + nlakes=len(pak_data), + ntables=0, + packagedata=pak_data, + pname="LAK-1", + connectiondata=con_data, + perioddata=p_data, + observations=lak_obs, + auxiliary=["TESTAUXVAR", "CONCENTRATION"], ) + # output control - oc = flopy.mf6.ModflowGwtoc( - gwt, - budget_filerecord=f"{gwtname}.cbc", - concentration_filerecord=f"{gwtname}.ucn", - concentrationprintrecord=[ + oc = flopy.mf6.ModflowGwfoc( + gwf, + budget_filerecord=f"{gwfname}.cbc", + head_filerecord=f"{gwfname}.hds", + headprintrecord=[ ("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL") ], - saverecord=[("CONCENTRATION", "ALL")], - printrecord=[("CONCENTRATION", "ALL"), ("BUDGET", "ALL")], + saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], + printrecord=[("HEAD", "LAST"), ("BUDGET", "LAST")], ) - fmi = flopy.mf6.ModflowGwtfmi(gwt, flow_imbalance_correction=True) - - # GWF GWT exchange - gwfgwt = flopy.mf6.ModflowGwfgwt( - sim, - exgtype="GWF6-GWT6", - exgmnamea=gwfname, - exgmnameb=gwtname, - filename=f"{name}.gwfgwt", - ) - - return sim, None - - -def eval_results(sim): - print("evaluating results...") - - # calculate volume of water and make sure it is conserved - name = ex[sim.idxsim] - gwfname = "gwf_" + name - gwtname = "gwt_" + name - fname = gwfname + ".lak.bin" - fname = os.path.join(sim.simpath, fname) - assert os.path.isfile(fname) - bobj = flopy.utils.HeadFile(fname, text="STAGE") - stage = bobj.get_alldata().flatten() - # print(stage) - - fname = gwfname + ".hds" - fname = os.path.join(sim.simpath, fname) - assert os.path.isfile(fname) - hobj = flopy.utils.HeadFile(fname) - head = hobj.get_data() - # print(head) - - fname = gwtname + ".ucn" - fname = os.path.join(sim.simpath, fname) - assert os.path.isfile(fname) - cobj = flopy.utils.HeadFile(fname, text="CONCENTRATION") - conc = cobj.get_data() - - fname = gwtname + ".lkt.bin" - fname = os.path.join(sim.simpath, fname) - assert os.path.isfile(fname) - cobj = flopy.utils.HeadFile(fname, text="CONCENTRATION") - clak = cobj.get_data().flatten() - - # calculate initial water volume - v0 = 3.5 * 2 # outermost columns - v0 += 2.5 * 2 # next innermost columns - v0 += 2.0 * 2 # next innermost columns - v0 += 1.0 * 1 # middle column - v0 = v0 * 0.3 # specific yield - - m0 = v0 * gwt_conc_list[sim.idxsim] - vl0 = (2.25 - 2.0) * 2 + (2.25 - 1.0) - m0 += vl0 * lak_conc_list[sim.idxsim] - v0 += vl0 - print(f"initial volume of water in model = {v0}") - print(f"initial mass of solute in model = {m0}") - - # calculate ending water volume in model - head = np.where(head > 1e10, -1e10, head) - botm = [3, 2, 1, 0] - top = [4, 3, 2, 1] - nlay, nrow, ncol = head.shape - v = 0 - m = 0.0 - for k in range(nlay): - for i in range(nrow): - for j in range(ncol): - h = min(head[k, i, j], top[k]) - dz = h - botm[k] - vcell = max(dz, 0.0) * 0.3 - v += vcell - m += vcell * conc[k, i, j] - - s = stage[-1] - vl = (s - 2.0) * 2 + (s - 1.0) - v = v + vl - m += vl * clak[0] - print(f"final volume of water in model = {v}") - print(f"final mass of solute in model = {m}") - - # check to make sure starting water volume same as equalized final volume - errmsg = f"initial and final water volume not equal: {v0} {v}" - assert np.allclose(v0, v), errmsg - - # check to make sure starting starting solute mass same as equalized solute mass - errmsg = f"initial and final solute mass not equal: {m0} {m}" - assert np.allclose(m0, m), errmsg - - # todo: add a better check of the lake concentrations - # assert False - - return - - -# - No need to change any code below -@pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + # create gwt model + transport = True + if transport: + gwt = flopy.mf6.ModflowGwt(sim, modelname=gwtname) + + imsgwt = flopy.mf6.ModflowIms( + sim, + print_option="ALL", + outer_dvclose=hclose, + outer_maximum=nouter, + under_relaxation="NONE", + inner_maximum=ninner, + inner_dvclose=hclose, + rcloserecord=f"{rclose} strict", + linear_acceleration="BICGSTAB", + scaling_method="NONE", + reordering_method="NONE", + relaxation_factor=relax, + filename=f"{gwtname}.ims", + ) + sim.register_ims_package(imsgwt, [gwt.name]) + + dis = flopy.mf6.ModflowGwtdis( + gwt, + nlay=nlay, + nrow=nrow, + ncol=ncol, + delr=delr, + delc=delc, + top=top, + botm=botm, + idomain=idomain, + ) + + # initial conditions + strt = data.gwt_conc + ic = flopy.mf6.ModflowGwtic(gwt, strt=strt) + + # advection + adv = flopy.mf6.ModflowGwtadv(gwt, scheme="UPSTREAM") + + # storage + porosity = 0.30 + sto = flopy.mf6.ModflowGwtmst(gwt, porosity=porosity) + + # sources + sourcerecarray = [ + (), + ] + ssm = flopy.mf6.ModflowGwtssm(gwt, sources=sourcerecarray) + + lak_conc = data.lak_conc + lktpackagedata = [ + (0, lak_conc, 99.0, 999.0, "mylake"), + ] + lkt = flopy.mf6.modflow.ModflowGwtlkt( + gwt, + boundnames=True, + save_flows=True, + print_input=True, + print_flows=True, + print_concentration=True, + concentration_filerecord=gwtname + ".lkt.bin", + budget_filerecord="gwtlak1.bud", + packagedata=lktpackagedata, + pname="LKT-1", + flow_package_name="LAK-1", + flow_package_auxiliary_name="CONCENTRATION", + auxiliary=["aux1", "aux2"], + ) + # output control + oc = flopy.mf6.ModflowGwtoc( + gwt, + budget_filerecord=f"{gwtname}.cbc", + concentration_filerecord=f"{gwtname}.ucn", + concentrationprintrecord=[ + ("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL") + ], + saverecord=[("CONCENTRATION", "ALL")], + printrecord=[("CONCENTRATION", "ALL"), ("BUDGET", "ALL")], + ) + + fmi = flopy.mf6.ModflowGwtfmi(gwt, flow_imbalance_correction=True) + + # GWF GWT exchange + gwfgwt = flopy.mf6.ModflowGwfgwt( + sim, + exgtype="GWF6-GWT6", + exgmnamea=gwfname, + exgmnameb=gwtname, + filename=f"{data.name}.gwfgwt", + ) + + return data, sim, None, self.eval_results + + def eval_results(self, sim, data): + print("evaluating results...") + + # calculate volume of water and make sure it is conserved + gwfname = "gwf_" + data.name + gwtname = "gwt_" + data.name + fname = gwfname + ".lak.bin" + fname = os.path.join(sim.simpath, fname) + assert os.path.isfile(fname) + bobj = flopy.utils.HeadFile(fname, text="STAGE") + stage = bobj.get_alldata().flatten() + # print(stage) + + fname = gwfname + ".hds" + fname = os.path.join(sim.simpath, fname) + assert os.path.isfile(fname) + hobj = flopy.utils.HeadFile(fname) + head = hobj.get_data() + # print(head) + + fname = gwtname + ".ucn" + fname = os.path.join(sim.simpath, fname) + assert os.path.isfile(fname) + cobj = flopy.utils.HeadFile(fname, text="CONCENTRATION") + conc = cobj.get_data() + + fname = gwtname + ".lkt.bin" + fname = os.path.join(sim.simpath, fname) + assert os.path.isfile(fname) + cobj = flopy.utils.HeadFile(fname, text="CONCENTRATION") + clak = cobj.get_data().flatten() + + # calculate initial water volume + v0 = 3.5 * 2 # outermost columns + v0 += 2.5 * 2 # next innermost columns + v0 += 2.0 * 2 # next innermost columns + v0 += 1.0 * 1 # middle column + v0 = v0 * 0.3 # specific yield + + m0 = v0 * data.gwt_conc + vl0 = (2.25 - 2.0) * 2 + (2.25 - 1.0) + m0 += vl0 * data.lak_conc + v0 += vl0 + print(f"initial volume of water in model = {v0}") + print(f"initial mass of solute in model = {m0}") + + # calculate ending water volume in model + head = np.where(head > 1e10, -1e10, head) + botm = [3, 2, 1, 0] + top = [4, 3, 2, 1] + nlay, nrow, ncol = head.shape + v = 0 + m = 0.0 + for k in range(nlay): + for i in range(nrow): + for j in range(ncol): + h = min(head[k, i, j], top[k]) + dz = h - botm[k] + vcell = max(dz, 0.0) * 0.3 + v += vcell + m += vcell * conc[k, i, j] + + s = stage[-1] + vl = (s - 2.0) * 2 + (s - 1.0) + v = v + vl + m += vl * clak[0] + print(f"final volume of water in model = {v}") + print(f"final mass of solute in model = {m}") + + # check to make sure starting water volume same as equalized final volume + errmsg = f"initial and final water volume not equal: {v0} {v}" + assert np.allclose(v0, v), errmsg + + # check to make sure starting starting solute mass same as equalized solute mass + errmsg = f"initial and final solute mass not equal: {m0} {m}" + assert np.allclose(m0, m), errmsg + + # todo: add a better check of the lake concentrations + + +@parametrize_with_cases( + "case", + cases=[ + GwfBuyLakCases, + ], ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(case, targets): + data, sim, cmp, evl = case + sim.write_simulation() + if cmp: + cmp.write_simulation() + + simulation = TestSimulation( + name=data.name, exe_dict=targets, exfunc=evl, idxsim=0 + ) + simulation.set_model( + sim.simulation_data.mfpath.get_sim_path(), testModel=False + ) + simulation.run() + simulation.compare() + evl(simulation, data) diff --git a/autotest/test_gwf_buy_maw01.py b/autotest/test_gwf_buy_maw01.py index 72887e337d7..09e96b37579 100644 --- a/autotest/test_gwf_buy_maw01.py +++ b/autotest/test_gwf_buy_maw01.py @@ -12,26 +12,15 @@ import os import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["buy_maw_01a"] # , 'buy_maw_01b', 'buy_maw_01c'] buy_on_list = [False] # , True, True] concbuylist = [0.0] # , 0., 35.] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -200,8 +189,7 @@ def eval_results(sim): print("evaluating results...") # calculate volume of water and make sure it is conserved - name = ex[sim.idxsim] - gwfname = "gwf_" + name + gwfname = "gwf_" + sim.name fname = gwfname + ".maw.bin" fname = os.path.join(sim.simpath, fname) assert os.path.isfile(fname) @@ -262,39 +250,17 @@ def eval_results(sim): print(msg) assert np.allclose(qmaw, -qgwf), msg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, 0, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=0 + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_buy_sfr01.py b/autotest/test_gwf_buy_sfr01.py index 73749476ff3..24f9bb12122 100644 --- a/autotest/test_gwf_buy_sfr01.py +++ b/autotest/test_gwf_buy_sfr01.py @@ -4,24 +4,13 @@ import os import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["buy_sfr_01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -387,9 +376,8 @@ def eval_results(sim): print("evaluating results...") # assign names - name = ex[sim.idxsim] - gwtname = "gwt_" + name - gwfname = "gwf_" + name + gwtname = "gwt_" + sim.name + gwfname = "gwf_" + sim.name # load the sft concentrations and make sure all values are correct fname = gwtname + ".sft.bin" @@ -468,42 +456,14 @@ def eval_results(sim): qcalc, qsim ), f"reach {n} flow {qcalc} not equal {qsim}" - # uncomment when testing - # assert False - - return - - -# - No need to change any code below -@pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), -) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +@pytest.mark.parametrize("name", ex) +def test_mf6model(name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, 0, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=0 + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_chd01.py b/autotest/test_gwf_chd01.py index 8f3bbf79a40..0dabc3ac06d 100644 --- a/autotest/test_gwf_chd01.py +++ b/autotest/test_gwf_chd01.py @@ -1,35 +1,14 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = [ "chd01", ] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -142,15 +121,11 @@ def build_model(idx, dir): def eval_model(sim): print("evaluating model...") - name = ex[sim.idxsim] - gwfname = "gwf_" + name + gwfname = "gwf_" + sim.name fpth = os.path.join(sim.simpath, f"{gwfname}.hds") - try: - hobj = flopy.utils.HeadFile(fpth, precision="double") - head = hobj.get_data().flatten() - except: - assert False, f'could not load data from "{fpth}"' + hobj = flopy.utils.HeadFile(fpth, precision="double") + head = hobj.get_data().flatten() # This is the answer to this problem. hres = np.linspace(1, 0, 100) @@ -158,42 +133,14 @@ def eval_model(sim): hres, head ), "simulated head do not match with known solution." - # comment when done testing - # assert False - - return - - -# - No need to change any code below -@pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), -) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +@pytest.mark.parametrize("name", ex) +def test_mf6model(name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, 0, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=0 + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_csub_db01_nr.py b/autotest/test_gwf_csub_db01_nr.py index 1e19d128f54..58b16e09d05 100644 --- a/autotest/test_gwf_csub_db01_nr.py +++ b/autotest/test_gwf_csub_db01_nr.py @@ -1,26 +1,10 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ( "csub_db01a", @@ -30,9 +14,7 @@ "csub_db01e", "csub_db01f", ) -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) + newtons = ( True, True, @@ -65,16 +47,9 @@ False, False, ) - -ddir = "data" - -# set replace_exe to None to use default executable -replace_exe = None - htol = None dtol = 1e-3 budtol = 0.01 - bud_lst = ( "CSUB-CGELASTIC_IN", "CSUB-CGELASTIC_OUT", @@ -432,51 +407,20 @@ def eval_comp(sim): print(" " + msg) -# - No need to change any code below - - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6( - Simulation( - dir, exfunc=eval_comp, exe_dict=r_exe, htol=htol, idxsim=idx - ) +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, + exe_dict=targets, + exfunc=eval_comp, + htol=htol, + idxsim=idx, + ), + str(function_tmpdir), ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, exfunc=eval_comp, exe_dict=replace_exe, htol=htol, idxsim=idx - ) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_csub_dbgeo01.py b/autotest/test_gwf_csub_dbgeo01.py index c0e0dd9678b..c899557c3a8 100644 --- a/autotest/test_gwf_csub_dbgeo01.py +++ b/autotest/test_gwf_csub_dbgeo01.py @@ -1,25 +1,12 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["csub_dbgeo01a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - ndcell = [19] strt = [0.0] chdh = [0] @@ -27,15 +14,6 @@ bso = [True] # sstate = [None, True] -# run all examples on Travis -# continuous_integration = [True for idx in range(len(exdirs))] -# the delay bed problems only run on the development version of MODFLOW-2005 -# set travis to True when version 1.13.0 is released -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None - # comparison data compdataa = [ 0.6829965295, @@ -345,7 +323,7 @@ def eval_sub(sim): assert False, f'could not load data from "{fpth}"' # set comparison data - tc0 = compdata[sim.idxsim] + tc0 = compdata[0] # calculate maximum absolute error diff = tc["TCOMP"] - tc0[:] @@ -379,53 +357,12 @@ def eval_sub(sim): sim.success = True print(" " + msg) - return - - -# - No need to change any code below - - -@pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), -) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6(Simulation(dir, exfunc=eval_sub, exe_dict=r_exe, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, exfunc=eval_sub, exe_dict=replace_exe, idxsim=idx - ) - test.run_mf6(sim) - - -# use python testmf6_csub_sub01.py --mf2005 mf2005devdbl -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +@pytest.mark.parametrize("name", ex) +def test_mf6model(name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, 0, str(function_tmpdir)) + test.run( + TestSimulation(name=name, exe_dict=targets, exfunc=eval_sub, idxsim=0), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_csub_inelastic.py b/autotest/test_gwf_csub_inelastic.py index c83b33fae4a..9d4e40575b7 100644 --- a/autotest/test_gwf_csub_inelastic.py +++ b/autotest/test_gwf_csub_inelastic.py @@ -1,42 +1,14 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation paktest = "csub" budtol = 1e-2 - ex = ["csub_de01a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - -updatemat = [None, True] -# run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None # static model data # spatial discretization @@ -280,50 +252,18 @@ def eval_void(sim): sim.success = True print(" " + msg) - return - -# - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - - test.run_mf6(Simulation(dir, exfunc=eval_void, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_void, idxsim=idx) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_void, idxsim=idx + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_csub_ndb01_nr.py b/autotest/test_gwf_csub_ndb01_nr.py index 9155a1d0260..0360ca612ea 100644 --- a/autotest/test_gwf_csub_ndb01_nr.py +++ b/autotest/test_gwf_csub_ndb01_nr.py @@ -1,26 +1,11 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from modflow_devtools.misc import is_in_ci +from simulation import TestSimulation ex = ( "csub_ndb01a", @@ -32,9 +17,6 @@ "csub_ndb01g", "csub_ndb01h", ) -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) newtons = ( True, False, @@ -65,12 +47,6 @@ False, False, ) - -ddir = "data" - -# set replace_exe to None to use default executable -replace_exe = None - htol = None dtol = 1e-3 budtol = 0.01 @@ -403,54 +379,21 @@ def eval_comp(sim): sim.success = True print(" " + msg) - return - - -# - No need to change any code below - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6( - Simulation( - dir, exfunc=eval_comp, exe_dict=r_exe, htol=htol, idxsim=idx - ) +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, + exe_dict=targets, + exfunc=eval_comp, + htol=htol, + idxsim=idx, + ), + str(function_tmpdir), ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, exfunc=eval_comp, exe_dict=replace_exe, htol=htol, idxsim=idx - ) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_csub_sk01.py b/autotest/test_gwf_csub_sk01.py index 168e941d93b..c53ec9fc470 100644 --- a/autotest/test_gwf_csub_sk01.py +++ b/autotest/test_gwf_csub_sk01.py @@ -1,537 +1,485 @@ import os +from typing import List, NamedTuple +import flopy import numpy as np -import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation - -ex = ["csub_sk01a", "csub_sk01b", "csub_sk01c"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -cvopt = [None, None, None] -constantcv = [True, True, True] -ndelaybeds = [0, 0, 0] - -cmppths = ["mf6-regression", "mf6-regression", "mf6-regression"] -tops = [0.0, 0.0, 150.0] -newtons = [False, True, True] - -ddir = "data" - -## run all examples on Travis -# continuous_integration = [False for idx in range(len(exdirs))] -continuous_integration = [True, True, True] - -# set replace_exe to None to use default executable -replace_exe = None - -htol = [None, None, 0.3] -dtol = 1e-3 -budtol = 0.01 - -bud_lst = [ - "CSUB-CGELASTIC_IN", - "CSUB-CGELASTIC_OUT", - "CSUB-WATERCOMP_IN", - "CSUB-WATERCOMP_OUT", -] - -# static model data -nlay, nrow, ncol = 3, 10, 10 -nper = 31 -perlen = [1.0] + [365.2500000 for i in range(nper - 1)] -nstp = [1] + [6 for i in range(nper - 1)] -tsmult = [1.0] + [1.3 for i in range(nper - 1)] -steady = [True] + [False for i in range(nper - 1)] -delr, delc = 1000.0, 2000.0 -top = 0.0 -botm = [-100, -150.0, -350.0] -zthick = [top - botm[0], botm[0] - botm[1], botm[1] - botm[2]] -strt = 100.0 -hnoflo = 1e30 -hdry = -1e30 - -# calculate hk -hk1fact = 1.0 / zthick[1] -hk1 = np.ones((nrow, ncol), dtype=float) * 0.5 * hk1fact -hk1[0, :] = 1000.0 * hk1fact -hk1[-1, :] = 1000.0 * hk1fact -hk1[:, 0] = 1000.0 * hk1fact -hk1[:, -1] = 1000.0 * hk1fact -hk = [20.0, hk1, 5.0] - -# calculate vka -vka = [1e6, 7.5e-5, 1e6] - -# set rest of npf variables -laytyp = [1, 0, 0] -laytypu = [4, 0, 0] -sy = 0.0 # [0.1, 0., 0.] - -nouter, ninner = 500, 300 -hclose, rclose, relax = 1e-9, 1e-6, 1.0 - -tdis_rc = [] -for idx in range(nper): - tdis_rc.append((perlen[idx], nstp[idx], tsmult[idx])) - -# all cells are active -ib = 1 - -# chd data -c = [] -c6 = [] -ccol = [3, 4, 5, 6] -for j in ccol: - c.append([0, nrow - 1, j, strt, strt]) - c6.append([(0, nrow - 1, j), strt]) -cd = {0: c} -cd6 = {0: c6} -maxchd = len(cd[0]) - -# pumping well data -wr = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3] -wc = [0, 1, 8, 9, 0, 9, 0, 9, 0, 0] -wrp = [2, 2, 3, 3] -wcp = [5, 6, 5, 6] -wq = [-14000.0, -8000.0, -5000.0, -3000.0] -d = [] -d6 = [] -for r, c, q in zip(wrp, wcp, wq): - d.append([2, r, c, q]) - d6.append([(2, r, c), q]) -wd = {1: d} -wd6 = {1: d6} -maxwel = len(wd[1]) - -# recharge data -q = 3000.0 / (delr * delc) -v = np.zeros((nrow, ncol), dtype=float) -for r, c in zip(wr, wc): - v[r, c] = q -rech = {0: v} - -# static ibc and sub data -sgm = 0.0 -sgs = 0.0 -omega = 1.0 -void = 0.82 -theta = void / (1.0 + void) -sw = 4.65120000e-10 * 9806.65000000 * theta - -# no delay bed data -nndb = 3 -lnd = [0, 1, 2] -hc = [botm[-1] for k in range(nlay)] -thicknd0 = [zthick[0], zthick[1], zthick[2]] -ccnd0 = [6e-6, 3e-6, 6e-6] -crnd0 = [6e-6, 3e-6, 6e-6] -sfv = [] -sfe = [] -for k in range(nlay): - sfv.append(ccnd0[k] * thicknd0[k]) - sfe.append(crnd0[k] * thicknd0[k]) - -# sub output data -ds15 = [0, 0, 0, 2052, 0, 0, 0, 0, 0, 0, 0, 0] -ds16 = [0, nper - 1, 0, nstp[-1] - 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1] - -# Build MODFLOW 6 files -def get_model(idx, ws): - name = ex[idx] - newton = newtons[idx] - newtonoptions = None - imsla = "CG" - if newton: - newtonoptions = "NEWTON" - imsla = "BICGSTAB" - - # build MODFLOW 6 files - sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws - ) - # create tdis package - tdis = flopy.mf6.ModflowTdis( - sim, time_units="DAYS", nper=nper, perioddata=tdis_rc - ) - - # create iterative model solution - ims = flopy.mf6.ModflowIms( - sim, - print_option="SUMMARY", - outer_dvclose=hclose, - outer_maximum=nouter, - under_relaxation="NONE", - inner_maximum=ninner, - inner_dvclose=hclose, - rcloserecord=rclose, - linear_acceleration=imsla, - scaling_method="NONE", - reordering_method="NONE", - relaxation_factor=relax, - ) - - # create gwf model - gwf = flopy.mf6.ModflowGwf( - sim, modelname=name, newtonoptions=newtonoptions - ) - - dis = flopy.mf6.ModflowGwfdis( - gwf, - nlay=nlay, - nrow=nrow, - ncol=ncol, - delr=delr, - delc=delc, - top=tops[idx], - botm=botm, - filename=f"{name}.dis", - ) - - # initial conditions - ic = flopy.mf6.ModflowGwfic(gwf, strt=strt, filename=f"{name}.ic") - - # node property flow - npf = flopy.mf6.ModflowGwfnpf( - gwf, - save_flows=False, - # dev_modflowusg_upstream_weighted_saturation=True, - icelltype=laytyp, - cvoptions=cvopt[idx], - k=hk, - k33=vka, - ) - # storage - sto = flopy.mf6.ModflowGwfsto( - gwf, - save_flows=False, - iconvert=laytyp, - ss=0.0, - sy=sy, - storagecoefficient=True, - steady_state={0: True}, - transient={1: True}, - ) +from framework import TestFramework +from pytest_cases import parametrize, parametrize_with_cases +from simulation import TestSimulation + + +class GwfCsubSkCases: + dtol: float = 1e-3 + budtol: float = 0.01 + bud_lst: List[str] = [ + "CSUB-CGELASTIC_IN", + "CSUB-CGELASTIC_OUT", + "CSUB-WATERCOMP_IN", + "CSUB-WATERCOMP_OUT", + ] - # recharge - rch = flopy.mf6.ModflowGwfrcha(gwf, readasarrays=True, recharge=rech) - - # wel file - wel = flopy.mf6.ModflowGwfwel( - gwf, - print_input=True, - print_flows=True, - maxbound=maxwel, - stress_period_data=wd6, - save_flows=False, + class Data(NamedTuple): + name: str + cvopt: str + constantcv: bool + ndelaybeds: int + top: float + newton: bool + htol: float + + @parametrize( + data=[ + Data("a", None, True, 0, 0, False, None), + Data("b", None, True, 0, 0, True, None), + Data("c", None, True, 0, 15, True, 0.3), + ] ) + def case_generator(self, function_tmpdir, data): + sim = self.get_model(data, function_tmpdir) + cmp = self.get_model(data, function_tmpdir / "mf6_regression") + return data, sim, cmp, self.eval_case + + def get_model(self, data, function_tmpdir): + name = data.name + newton = data.newton + newtonoptions = None + imsla = "CG" + if newton: + newtonoptions = "NEWTON" + imsla = "BICGSTAB" + + # static model data + nlay, nrow, ncol = 3, 10, 10 + nper = 31 + perlen = [1.0] + [365.2500000 for i in range(nper - 1)] + nstp = [1] + [6 for i in range(nper - 1)] + tsmult = [1.0] + [1.3 for i in range(nper - 1)] + steady = [True] + [False for i in range(nper - 1)] + delr, delc = 1000.0, 2000.0 + top = 0.0 + botm = [-100, -150.0, -350.0] + zthick = [top - botm[0], botm[0] - botm[1], botm[1] - botm[2]] + strt = 100.0 + hnoflo = 1e30 + hdry = -1e30 + + # calculate hk + hk1fact = 1.0 / zthick[1] + hk1 = np.ones((nrow, ncol), dtype=float) * 0.5 * hk1fact + hk1[0, :] = 1000.0 * hk1fact + hk1[-1, :] = 1000.0 * hk1fact + hk1[:, 0] = 1000.0 * hk1fact + hk1[:, -1] = 1000.0 * hk1fact + hk = [20.0, hk1, 5.0] + + # calculate vka + vka = [1e6, 7.5e-5, 1e6] + + # set rest of npf variables + laytyp = [1, 0, 0] + laytypu = [4, 0, 0] + sy = 0.0 # [0.1, 0., 0.] + + nouter, ninner = 500, 300 + hclose, rclose, relax = 1e-9, 1e-6, 1.0 + + tdis_rc = [] + for idx in range(nper): + tdis_rc.append((perlen[idx], nstp[idx], tsmult[idx])) + + # all cells are active + ib = 1 + + # chd data + c = [] + c6 = [] + ccol = [3, 4, 5, 6] + for j in ccol: + c.append([0, nrow - 1, j, strt, strt]) + c6.append([(0, nrow - 1, j), strt]) + cd = {0: c} + cd6 = {0: c6} + maxchd = len(cd[0]) + + # pumping well data + wr = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3] + wc = [0, 1, 8, 9, 0, 9, 0, 9, 0, 0] + wrp = [2, 2, 3, 3] + wcp = [5, 6, 5, 6] + wq = [-14000.0, -8000.0, -5000.0, -3000.0] + d = [] + d6 = [] + for r, c, q in zip(wrp, wcp, wq): + d.append([2, r, c, q]) + d6.append([(2, r, c), q]) + wd = {1: d} + wd6 = {1: d6} + maxwel = len(wd[1]) + + # recharge data + q = 3000.0 / (delr * delc) + v = np.zeros((nrow, ncol), dtype=float) + for r, c in zip(wr, wc): + v[r, c] = q + rech = {0: v} + + # static ibc and sub data + sgm = 0.0 + sgs = 0.0 + omega = 1.0 + void = 0.82 + theta = void / (1.0 + void) + sw = 4.65120000e-10 * 9806.65000000 * theta + + # no delay bed data + nndb = 3 + lnd = [0, 1, 2] + hc = [botm[-1] for k in range(nlay)] + thicknd0 = [zthick[0], zthick[1], zthick[2]] + ccnd0 = [6e-6, 3e-6, 6e-6] + crnd0 = [6e-6, 3e-6, 6e-6] + sfv = [] + sfe = [] + for k in range(nlay): + sfv.append(ccnd0[k] * thicknd0[k]) + sfe.append(crnd0[k] * thicknd0[k]) + + # sub output data + ds15 = [0, 0, 0, 2052, 0, 0, 0, 0, 0, 0, 0, 0] + ds16 = [ + 0, + nper - 1, + 0, + nstp[-1] - 1, + 0, + 0, + 1, + 1, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + ] + + # build MODFLOW 6 files + sim = flopy.mf6.MFSimulation( + sim_name=name, version="mf6", exe_name="mf6", sim_ws=str(function_tmpdir) + ) + # create tdis package + tdis = flopy.mf6.ModflowTdis( + sim, time_units="DAYS", nper=nper, perioddata=tdis_rc + ) - # chd files - chd = flopy.mf6.modflow.mfgwfchd.ModflowGwfchd( - gwf, maxbound=maxchd, stress_period_data=cd6, save_flows=False - ) - # csub files - opth = f"{name}.csub.obs" - csub = flopy.mf6.ModflowGwfcsub( - gwf, - head_based=True, - save_flows=True, - ninterbeds=0, - cg_theta=theta, - cg_ske_cr=crnd0, - packagedata=None, - ) - obspos = [(0, 4, 4), (1, 4, 4), (2, 4, 4)] - obstype = ["compaction-cell", "csub-cell"] - obstag = ["tcomp", "csub"] - obsarr = [] - for iobs, cobs in enumerate(obstype): - for jobs, otup in enumerate(obspos): - otag = f"{obstag[iobs]}{jobs + 1}" - obsarr.append((otag, cobs, otup)) - - obsarr2 = [] - obstype2 = [ - "csub", - "inelastic-csub", - "elastic-csub", - "sk", - "ske", - "thickness", - "theta", - "interbed-compaction", - "inelastic-compaction", - "elastic-compaction", - "delay-flowtop", - "delay-flowbot", - ] - iobs = 0 - for cobs in obstype2: - iobs += 1 - otag = f"obs{iobs:03d}" - obsarr2.append((otag, cobs, (0,))) - - obstype3 = [ - "delay-preconstress", - "delay-head", - "delay-gstress", - "delay-estress", - "delay-compaction", - "delay-thickness", - "delay-theta", - ] - for cobs in obstype3: - iobs += 1 - otag = f"obs{iobs:03d}" - obsarr2.append((otag, cobs, (0,), (0,))) - - obsarr3 = [] - obstype4 = [ - "gstress-cell", - "estress-cell", - "thickness-cell", - "coarse-csub", - "wcomp-csub-cell", - "coarse-compaction", - "coarse-theta", - "coarse-thickness", - "csub-cell", - "ske-cell", - "sk-cell", - "theta-cell", - "compaction-cell", - ] - for cobs in obstype4: - iobs += 1 - otag = f"obs{iobs:03d}" - obsarr3.append((otag, cobs, obspos[-1])) - - orecarray = {} - orecarray["csub_obs.csv"] = obsarr - orecarray["interbed_obs.csv"] = obsarr2 - orecarray["coarse_cell_obs.csv"] = obsarr3 - - csub_obs_package = csub.obs.initialize( - filename=opth, digits=10, print_input=True, continuous=orecarray - ) + # create iterative model solution + ims = flopy.mf6.ModflowIms( + sim, + print_option="SUMMARY", + outer_dvclose=hclose, + outer_maximum=nouter, + under_relaxation="NONE", + inner_maximum=ninner, + inner_dvclose=hclose, + rcloserecord=rclose, + linear_acceleration=imsla, + scaling_method="NONE", + reordering_method="NONE", + relaxation_factor=relax, + ) - # output control - oc = flopy.mf6.ModflowGwfoc( - gwf, - budget_filerecord=f"{name}.cbc", - head_filerecord=f"{name}.hds", - headprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")], - saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], - printrecord=[("HEAD", "LAST"), ("BUDGET", "ALL")], - ) + # create gwf model + gwf = flopy.mf6.ModflowGwf( + sim, modelname=name, newtonoptions=newtonoptions + ) - return sim + dis = flopy.mf6.ModflowGwfdis( + gwf, + nlay=nlay, + nrow=nrow, + ncol=ncol, + delr=delr, + delc=delc, + top=data.top, + botm=botm, + filename=f"{name}.dis", + ) + # initial conditions + ic = flopy.mf6.ModflowGwfic(gwf, strt=strt, filename=f"{name}.ic") + + # node property flow + npf = flopy.mf6.ModflowGwfnpf( + gwf, + save_flows=False, + # dev_modflowusg_upstream_weighted_saturation=True, + icelltype=laytyp, + cvoptions=data.cvopt, + k=hk, + k33=vka, + ) + # storage + sto = flopy.mf6.ModflowGwfsto( + gwf, + save_flows=False, + iconvert=laytyp, + ss=0.0, + sy=sy, + storagecoefficient=True, + steady_state={0: True}, + transient={1: True}, + ) -# SUB package problem 3 -def build_model(idx, dir): - ws = dir - sim = get_model(idx, ws) + # recharge + rch = flopy.mf6.ModflowGwfrcha(gwf, readasarrays=True, recharge=rech) + + # wel file + wel = flopy.mf6.ModflowGwfwel( + gwf, + print_input=True, + print_flows=True, + maxbound=maxwel, + stress_period_data=wd6, + save_flows=False, + ) - ws = os.path.join(dir, cmppths[idx]) - mc = get_model(idx, ws) + # chd files + chd = flopy.mf6.modflow.mfgwfchd.ModflowGwfchd( + gwf, maxbound=maxchd, stress_period_data=cd6, save_flows=False + ) + # csub files + opth = f"{name}.csub.obs" + csub = flopy.mf6.ModflowGwfcsub( + gwf, + head_based=True, + save_flows=True, + ninterbeds=0, + cg_theta=theta, + cg_ske_cr=crnd0, + packagedata=None, + ) + obspos = [(0, 4, 4), (1, 4, 4), (2, 4, 4)] + obstype = ["compaction-cell", "csub-cell"] + obstag = ["tcomp", "csub"] + obsarr = [] + for iobs, cobs in enumerate(obstype): + for jobs, otup in enumerate(obspos): + otag = f"{obstag[iobs]}{jobs + 1}" + obsarr.append((otag, cobs, otup)) + + obsarr2 = [] + obstype2 = [ + "csub", + "inelastic-csub", + "elastic-csub", + "sk", + "ske", + "thickness", + "theta", + "interbed-compaction", + "inelastic-compaction", + "elastic-compaction", + "delay-flowtop", + "delay-flowbot", + ] + iobs = 0 + for cobs in obstype2: + iobs += 1 + otag = f"obs{iobs:03d}" + obsarr2.append((otag, cobs, (0,))) + + obstype3 = [ + "delay-preconstress", + "delay-head", + "delay-gstress", + "delay-estress", + "delay-compaction", + "delay-thickness", + "delay-theta", + ] + for cobs in obstype3: + iobs += 1 + otag = f"obs{iobs:03d}" + obsarr2.append((otag, cobs, (0,), (0,))) + + obsarr3 = [] + obstype4 = [ + "gstress-cell", + "estress-cell", + "thickness-cell", + "coarse-csub", + "wcomp-csub-cell", + "coarse-compaction", + "coarse-theta", + "coarse-thickness", + "csub-cell", + "ske-cell", + "sk-cell", + "theta-cell", + "compaction-cell", + ] + for cobs in obstype4: + iobs += 1 + otag = f"obs{iobs:03d}" + obsarr3.append((otag, cobs, obspos[-1])) + + orecarray = {} + orecarray["csub_obs.csv"] = obsarr + orecarray["interbed_obs.csv"] = obsarr2 + orecarray["coarse_cell_obs.csv"] = obsarr3 + + csub_obs_package = csub.obs.initialize( + filename=opth, digits=10, print_input=True, continuous=orecarray + ) - return sim, mc + # output control + oc = flopy.mf6.ModflowGwfoc( + gwf, + budget_filerecord=f"{name}.cbc", + head_filerecord=f"{name}.hds", + headprintrecord=[ + ("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL") + ], + saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], + printrecord=[("HEAD", "LAST"), ("BUDGET", "ALL")], + ) + return sim -def eval_comp(sim): - print("evaluating compaction...") + def eval_case(self, sim, data): + print("evaluating compaction...") - # MODFLOW 6 total compaction results - fpth = os.path.join(sim.simpath, "csub_obs.csv") - try: + # MODFLOW 6 total compaction results + fpth = os.path.join(sim.simpath, "csub_obs.csv") tc = np.genfromtxt(fpth, names=True, delimiter=",") - except: - assert False, f'could not load data from "{fpth}"' - # regression compaction results - cpth = cmppths[sim.idxsim] - fpth = os.path.join(sim.simpath, cpth, "csub_obs.csv") - try: + # regression compaction results + cpth = "mf6_regression" + fpth = os.path.join(sim.simpath, cpth, "csub_obs.csv") tc0 = np.genfromtxt(fpth, names=True, delimiter=",") - except: - assert False, f'could not load data from "{fpth}"' - # calculate maximum absolute error - diff = tc["TCOMP3"] - tc0["TCOMP3"] - diffmax = np.abs(diff).max() - msg = f"maximum absolute total-compaction difference ({diffmax}) " + # calculate maximum absolute error + diff = tc["TCOMP3"] - tc0["TCOMP3"] + diffmax = np.abs(diff).max() + msg = f"maximum absolute total-compaction difference ({diffmax}) " - # write summary - fpth = os.path.join( - sim.simpath, f"{os.path.basename(sim.name)}.comp.cmp.out" - ) - f = open(fpth, "w") - for i in range(diff.shape[0]): - line = f"{tc0['time'][i]:10.2g}" - line += f"{tc['TCOMP3'][i]:10.2g}" - line += f"{tc0['TCOMP3'][i]:10.2g}" - line += f"{diff[i]:10.2g}" - f.write(line + "\n") - f.close() - - if diffmax > dtol: - sim.success = False - msg += f"exceeds {dtol}" - assert diffmax < dtol, msg - else: - sim.success = True - print(" " + msg) - - # get results from listing file - fpth = os.path.join(sim.simpath, f"{os.path.basename(sim.name)}.lst") - budl = flopy.utils.Mf6ListBudget(fpth) - names = list(bud_lst) - d0 = budl.get_budget(names=names)[0] - dtype = d0.dtype - nbud = d0.shape[0] - - # get results from cbc file - cbc_bud = ["CSUB-CGELASTIC", "CSUB-WATERCOMP"] - d = np.recarray(nbud, dtype=dtype) - for key in bud_lst: - d[key] = 0.0 - fpth = os.path.join(sim.simpath, f"{os.path.basename(sim.name)}.cbc") - cobj = flopy.utils.CellBudgetFile(fpth, precision="double") - kk = cobj.get_kstpkper() - times = cobj.get_times() - for idx, (k, t) in enumerate(zip(kk, times)): - for text in cbc_bud: - qin = 0.0 - qout = 0.0 - v = cobj.get_data(kstpkper=k, text=text)[0] - for kk in range(v.shape[0]): - for ii in range(v.shape[1]): - for jj in range(v.shape[2]): - vv = v[kk, ii, jj] - if vv < 0.0: - qout -= vv - else: - qin += vv - d["totim"][idx] = t - d["time_step"][idx] = k[0] - d["stress_period"] = k[1] - key = f"{text}_IN" - d[key][idx] = qin - key = f"{text}_OUT" - d[key][idx] = qout - - diff = np.zeros((nbud, len(bud_lst)), dtype=float) - for idx, key in enumerate(bud_lst): - diff[:, idx] = d0[key] - d[key] - diffmax = np.abs(diff).max() - msg = f"maximum absolute total-budget difference ({diffmax}) " - - # write summary - fpth = os.path.join( - sim.simpath, f"{os.path.basename(sim.name)}.bud.cmp.out" - ) - f = open(fpth, "w") - for i in range(diff.shape[0]): - if i == 0: - line = f"{'TIME':>10s}" - for idx, key in enumerate(bud_lst): - line += f"{key + '_LST':>25s}" - line += f"{key + '_CBC':>25s}" - line += f"{key + '_DIF':>25s}" + # write summary + fpth = os.path.join( + sim.simpath, f"{os.path.basename(sim.name)}.comp.cmp.out" + ) + f = open(fpth, "w") + for i in range(diff.shape[0]): + line = f"{tc0['time'][i]:10.2g}" + line += f"{tc['TCOMP3'][i]:10.2g}" + line += f"{tc0['TCOMP3'][i]:10.2g}" + line += f"{diff[i]:10.2g}" f.write(line + "\n") - line = f"{d['totim'][i]:10g}" - for idx, key in enumerate(bud_lst): - line += f"{d0[key][i]:25g}" - line += f"{d[key][i]:25g}" - line += f"{diff[i, idx]:25g}" - f.write(line + "\n") - f.close() - - if diffmax > budtol: - sim.success = False - msg += f"exceeds {dtol}" - assert diffmax < dtol, msg - else: - sim.success = True - print(" " + msg) - - return - - -# - No need to change any code below - - -@pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), -) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6( - Simulation( - dir, - exfunc=eval_comp, - htol=htol[idx], - idxsim=idx, - mf6_regression=True, + f.close() + + if diffmax > self.dtol: + sim.success = False + msg += f"exceeds {self.dtol}" + assert diffmax < self.dtol, msg + else: + sim.success = True + print(" " + msg) + + # get results from listing file + fpth = os.path.join(sim.simpath, f"{os.path.basename(sim.name)}.lst") + budl = flopy.utils.Mf6ListBudget(fpth) + names = list(self.bud_lst) + d0 = budl.get_budget(names=names)[0] + dtype = d0.dtype + nbud = d0.shape[0] + + # get results from cbc file + cbc_bud = ["CSUB-CGELASTIC", "CSUB-WATERCOMP"] + d = np.recarray(nbud, dtype=dtype) + for key in self.bud_lst: + d[key] = 0.0 + fpth = os.path.join(sim.simpath, f"{os.path.basename(sim.name)}.cbc") + cobj = flopy.utils.CellBudgetFile(fpth, precision="double") + kk = cobj.get_kstpkper() + times = cobj.get_times() + for idx, (k, t) in enumerate(zip(kk, times)): + for text in cbc_bud: + qin = 0.0 + qout = 0.0 + v = cobj.get_data(kstpkper=k, text=text)[0] + for kk in range(v.shape[0]): + for ii in range(v.shape[1]): + for jj in range(v.shape[2]): + vv = v[kk, ii, jj] + if vv < 0.0: + qout -= vv + else: + qin += vv + d["totim"][idx] = t + d["time_step"][idx] = k[0] + d["stress_period"] = k[1] + key = f"{text}_IN" + d[key][idx] = qin + key = f"{text}_OUT" + d[key][idx] = qout + + diff = np.zeros((nbud, len(self.bud_lst)), dtype=float) + for idx, key in enumerate(self.bud_lst): + diff[:, idx] = d0[key] - d[key] + diffmax = np.abs(diff).max() + msg = f"maximum absolute total-budget difference ({diffmax}) " + + # write summary + fpth = os.path.join( + sim.simpath, f"{os.path.basename(sim.name)}.bud.cmp.out" ) + f = open(fpth, "w") + for i in range(diff.shape[0]): + if i == 0: + line = f"{'TIME':>10s}" + for idx, key in enumerate(self.bud_lst): + line += f"{key + '_LST':>25s}" + line += f"{key + '_CBC':>25s}" + line += f"{key + '_DIF':>25s}" + f.write(line + "\n") + line = f"{d['totim'][i]:10g}" + for idx, key in enumerate(self.bud_lst): + line += f"{d0[key][i]:25g}" + line += f"{d[key][i]:25g}" + line += f"{diff[i, idx]:25g}" + f.write(line + "\n") + f.close() + + if diffmax > self.budtol: + sim.success = False + msg += f"exceeds {self.dtol}" + assert diffmax < self.dtol, msg + else: + sim.success = True + print(" " + msg) + + +@parametrize_with_cases( + "case", + cases=[ + GwfCsubSkCases, + ], +) +def test_mf6model(case, targets): + data, sim, cmp, evl = case + sim.write_simulation() + if cmp: + cmp.write_simulation() + test = TestSimulation( + name=data.name, + exe_dict=targets, + exfunc=evl, + idxsim=0, + mf6_regression=True, ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, - exfunc=eval_comp, - htol=htol[idx], - idxsim=idx, - mf6_regression=True, - ) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() + test.set_model(sim.simulation_data.mfpath.get_sim_path(), testModel=False) + test.run() + test.compare() + evl(test, data) diff --git a/autotest/test_gwf_csub_sk02.py b/autotest/test_gwf_csub_sk02.py index d87765feed8..5ae15cf0b0f 100644 --- a/autotest/test_gwf_csub_sk02.py +++ b/autotest/test_gwf_csub_sk02.py @@ -1,52 +1,23 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from modflow_devtools.misc import is_in_ci +from simulation import TestSimulation ex = ["csub_sk02a", "csub_sk02b", "csub_sk02c", "csub_sk02d"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -constantcv = [True for idx in range(len(exdirs))] - -cmppths = ["mf6-regression" for idx in range(len(exdirs))] -tops = [150.0 for idx in range(len(exdirs))] -newtons = [True for idx in range(len(exdirs))] +constantcv = [True for idx in range(len(ex))] +cmppths = ["mf6_regression" for idx in range(len(ex))] +tops = [150.0 for idx in range(len(ex))] +newtons = [True for idx in range(len(ex))] ump = [None, None, True, True] iump = [0, 0, 1, 1] -eslag = [True for idx in range(len(exdirs))] +eslag = [True for idx in range(len(ex))] icrcc = [0, 1, 0, 1] - -ddir = "data" - -## run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None - -htol = [None for idx in range(len(exdirs))] +htol = [None for idx in range(len(ex))] dtol = 1e-3 - bud_lst = [ "CSUB-CGELASTIC_IN", "CSUB-CGELASTIC_OUT", @@ -481,71 +452,22 @@ def eval_comp(sim): sim.success = True print(" " + msg) - return - - -# - No need to change any code below - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6( - Simulation( - dir, +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_comp, - exe_dict=r_exe, htol=htol[idx], idxsim=idx, mf6_regression=True, - ) + ), + str(function_tmpdir), ) - - return - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, - exfunc=eval_comp, - exe_dict=replace_exe, - htol=htol[idx], - idxsim=idx, - mf6_regression=True, - ) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_csub_sk03.py b/autotest/test_gwf_csub_sk03.py index ce7e9e7685c..f886dba8a4b 100644 --- a/autotest/test_gwf_csub_sk03.py +++ b/autotest/test_gwf_csub_sk03.py @@ -1,50 +1,19 @@ import datetime import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["csub_sk03a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -constantcv = [True for idx in range(len(exdirs))] - -cmppths = ["mf6-regression" for idx in range(len(exdirs))] -newtons = [True for idx in range(len(exdirs))] - +constantcv = [True for idx in range(len(ex))] +cmppths = ["mf6_regression" for idx in range(len(ex))] +newtons = [True for idx in range(len(ex))] icrcc = [0, 1, 0, 1] - -ddir = "data" - -## run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None - -htol = [None for idx in range(len(exdirs))] +htol = [None for idx in range(len(ex))] dtol = 1e-3 - bud_lst = [ "CSUB-CGELASTIC_IN", "CSUB-CGELASTIC_OUT", @@ -628,70 +597,23 @@ def eval_comp(sim): sim.success = True print(" " + msg) - return - - -# - No need to change any code below - +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6( - Simulation( - dir, +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_comp, - exe_dict=r_exe, htol=htol[idx], idxsim=idx, mf6_regression=True, - ) + ), + str(function_tmpdir), ) - - return - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, - exfunc=eval_comp, - exe_dict=replace_exe, - htol=htol[idx], - idxsim=idx, - mf6_regression=True, - ) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_csub_sk04_nr.py b/autotest/test_gwf_csub_sk04_nr.py index 5ba5545ee75..edb9f0409e8 100644 --- a/autotest/test_gwf_csub_sk04_nr.py +++ b/autotest/test_gwf_csub_sk04_nr.py @@ -1,26 +1,10 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ( "csub_sk04a", @@ -28,9 +12,6 @@ "csub_sk04c", "csub_sk04d", ) -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) newtons = (True, False, True, False) stress_lag = ( None, @@ -39,11 +20,6 @@ True, ) -ddir = "data" - -# set replace_exe to None to use default executable -replace_exe = None - htol = None dtol = 1e-3 budtol = 0.01 @@ -351,54 +327,21 @@ def eval_comp(sim): sim.success = True print(" " + msg) - return - - -# - No need to change any code below - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6( - Simulation( - dir, exfunc=eval_comp, exe_dict=r_exe, htol=htol, idxsim=idx - ) +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, + exe_dict=targets, + exfunc=eval_comp, + htol=htol, + idxsim=idx, + ), + str(function_tmpdir), ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, exfunc=eval_comp, exe_dict=replace_exe, htol=htol, idxsim=idx - ) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_csub_sub01.py b/autotest/test_gwf_csub_sub01.py index 5302a6ae736..4327c62e3fb 100644 --- a/autotest/test_gwf_csub_sub01.py +++ b/autotest/test_gwf_csub_sub01.py @@ -1,49 +1,17 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation paktest = "csub" budtol = 1e-2 - ex = ["csub_sub01a", "csub_sub01b"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - compression_indices = [None, True] - ndcell = [19] * len(ex) -# run all examples on Travis -# continuous_integration = [True for idx in range(len(exdirs))] -# the delay bed problems only run on the development version of MODFLOW-2005 -# set travis to True when version 1.13.0 is released -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None - # static model data # spatial discretization nlay, nrow, ncol = 1, 1, 3 @@ -254,7 +222,7 @@ def build_model(idx, dir): sim = get_model(idx, ws) # build MODFLOW-2005 files - ws = os.path.join(dir, "mf6-regression") + ws = os.path.join(dir, "mf6_regression") mc = get_model(idx, ws) return sim, mc @@ -271,7 +239,7 @@ def eval_sub(sim): assert False, f'could not load data from "{fpth}"' # comparison total compaction results - fpth = os.path.join(sim.simpath, "mf6-regression", "csub_obs.csv") + fpth = os.path.join(sim.simpath, "mf6_regression", "csub_obs.csv") try: tc0 = np.genfromtxt(fpth, names=True, delimiter=",") except: @@ -409,50 +377,21 @@ def cbc_compare(sim): sim.success = True print(" " + msg) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # run the test model - test.build_mf6_models(build_model, idx, exdir) - - test.run_mf6( - Simulation( - exdir, +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_sub, idxsim=idx, mf6_regression=True, - ) + ), + str(function_tmpdir), ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - sim = Simulation( - exdir, - exfunc=eval_sub, - idxsim=idx, - mf6_regression=True, - ) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_csub_sub01_adjmat.py b/autotest/test_gwf_csub_sub01_adjmat.py index de5c09ca06b..694799c26da 100644 --- a/autotest/test_gwf_csub_sub01_adjmat.py +++ b/autotest/test_gwf_csub_sub01_adjmat.py @@ -1,50 +1,19 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation paktest = "csub" budtol = 1e-2 compdir = "mf6" ex = ["csub_sub01_adj"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - compression_indices = [None] - ndcell = [19] * len(ex) -# run all examples on Travis -# continuous_integration = [True for idx in range(len(exdirs))] -# the delay bed problems only run on the development version of MODFLOW-2005 -# set travis to True when version 1.13.0 is released -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None - # static model data # spatial discretization nlay, nrow, ncol = 1, 1, 3 @@ -327,8 +296,8 @@ def eval_sub(sim): # calculate theta and porosity from interbed cell compaction calci = np.zeros((comp.shape[0]), dtype=dtype) - thickini = 1.0 / ndcell[sim.idxsim] - for n in range(ndcell[sim.idxsim]): + thickini = 1.0 / ndcell[0] + for n in range(ndcell[0]): tagc = f"DBCOMP{n + 1:02d}" tagb = f"DBTHICK{n + 1:02d}" tagp = f"DBPORO{n + 1:02d}" @@ -378,8 +347,6 @@ def eval_sub(sim): # compare budgets cbc_compare(sim) - return - # compare cbc and lst budgets def cbc_compare(sim): @@ -467,6 +434,8 @@ def cbc_compare(sim): f.write(line + "\n") f.close() + dtol = 1e-6 + if diffmax > budtol: sim.success = False msg += f"exceeds {dtol}" @@ -475,54 +444,12 @@ def cbc_compare(sim): sim.success = True print(" " + msg) - return - - -# - No need to change any code below - -@pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), -) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6(Simulation(dir, exfunc=eval_sub, exe_dict=r_exe, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, exfunc=eval_sub, exe_dict=replace_exe, idxsim=idx - ) - test.run_mf6(sim) - return - - -# use python testmf6_csub_sub01.py --mf2005 mf2005devdbl -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +@pytest.mark.parametrize("name", ex) +def test_mf6model(name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, 0, str(function_tmpdir)) + test.run( + TestSimulation(name=name, exe_dict=targets, exfunc=eval_sub, idxsim=0), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_csub_sub01_elastic.py b/autotest/test_gwf_csub_sub01_elastic.py index baec5b1bfe5..815910827b4 100644 --- a/autotest/test_gwf_csub_sub01_elastic.py +++ b/autotest/test_gwf_csub_sub01_elastic.py @@ -1,47 +1,18 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation cmppth = "mf6" - paktest = "csub" dtol = 1e-3 budtol = 1e-2 - ex = ["csub_sub01_elasa"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - ndcell = [19] -# run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None - # static model data # spatial discretization nlay, nrow, ncol = 1, 1, 3 @@ -371,51 +342,17 @@ def cbc_compare(sim): sim.success = True print(" " + msg) - return - - -# - No need to change any code below - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6(Simulation(dir, exfunc=eval_sub, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_sub, idxsim=idx) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_sub, idxsim=idx + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_csub_sub01_pch.py b/autotest/test_gwf_csub_sub01_pch.py index 73632cf0efb..b4b12c81e5b 100644 --- a/autotest/test_gwf_csub_sub01_pch.py +++ b/autotest/test_gwf_csub_sub01_pch.py @@ -1,48 +1,17 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation paktest = "csub" budtol = 1e-2 - compdir = "mf6" ex = ["csub_sub01_pch"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - ndcell = [19] * len(ex) -# run all examples on Travis -# continuous_integration = [True for idx in range(len(exdirs))] -# the delay bed problems only run on the development version of MODFLOW-2005 -# set travis to True when version 1.13.0 is released -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None - # static model data # spatial discretization nlay, nrow, ncol = 1, 1, 3 @@ -304,8 +273,6 @@ def eval_sub(sim): # compare budgets cbc_compare(sim) - return - # compare cbc and lst budgets def cbc_compare(sim): @@ -393,6 +360,8 @@ def cbc_compare(sim): f.write(line + "\n") f.close() + dtol = 1e-6 + if diffmax > budtol: sim.success = False msg += f"exceeds {dtol}" @@ -402,50 +371,16 @@ def cbc_compare(sim): print(" " + msg) -# - No need to change any code below - - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6(Simulation(dir, exfunc=eval_sub, exe_dict=r_exe, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, exfunc=eval_sub, exe_dict=replace_exe, idxsim=idx - ) - test.run_mf6(sim) - - -# use python testmf6_csub_sub01.py --mf2005 mf2005devdbl -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_sub, idxsim=idx + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_csub_sub02.py b/autotest/test_gwf_csub_sub02.py index 858bfb6d241..7596dfc1875 100644 --- a/autotest/test_gwf_csub_sub02.py +++ b/autotest/test_gwf_csub_sub02.py @@ -1,25 +1,9 @@ import os +import flopy import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = [ "csub_sub02a", @@ -28,12 +12,7 @@ "csub_sub02d", "csub_sub02e", ] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" -cmppth = "mf6-regression" - +cmppth = "mf6_regression" cg_ske = 1.14e-3 / (500.0 - 20.0) cg_S = cg_ske * (500.0 - 20.0) ss = [cg_S, cg_S, cg_ske, cg_ske, cg_S] @@ -41,12 +20,6 @@ cdelay = [False, True, False, True, True] ndelaycells = [None, 19, None, 19, 19] -# run all examples on Travis -continuous_integration = [True for e in ex] - -# set replace_exe to None to use default executable -replace_exe = None - # static model data nlay, nrow, ncol = 1, 1, 1 nper = 10 @@ -236,50 +209,14 @@ def build_model(idx, dir): return sim, mc -# - No need to change any code below - - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - if is_CI and not continuous_integration[idx]: - return - - # run the test model - test.run_mf6(Simulation(dir, mf6_regression=True)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for dir in exdirs: - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, - mf6_regression=True, - ) - test.run_mf6(sim) - - return - - -# use python test_gwf_csub_sub02.py --mf2005 mf2005devdbl -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation(name=name, exe_dict=targets, mf6_regression=True), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_csub_sub03.py b/autotest/test_gwf_csub_sub03.py index 67b3ab36e5b..dbb848c2b3c 100644 --- a/autotest/test_gwf_csub_sub03.py +++ b/autotest/test_gwf_csub_sub03.py @@ -1,50 +1,20 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from conftest import project_root_path +from framework import TestFramework +from simulation import TestSimulation ex = ["csub_sub03a", "csub_sub03b"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -cmppth = "mf6-regression" - - +cmppth = "mf6_regression" cvopt = [None, None, None] constantcv = [True, True] ndelaybeds = [0, 2] ndelaycells = [None, 39] - -ddir = "data" - -## run all examples on Travis -continuous_integration = [True for e in ex] - -# set replace_exe to None to use default executable -replace_exe = None - htol = [None, None, None] dtol = 1e-3 - bud_lst = [ "CSUB-ELASTIC_IN", "CSUB-INELASTIC_IN", @@ -161,7 +131,9 @@ nz = [1, 1] dstart = [] for k in ldnd: - pth = os.path.join(ddir, f"ibc03_dstart{k + 1}.ref") + pth = str( + project_root_path / "autotest" / "data" / f"ibc03_dstart{k + 1}.ref" + ) v = np.genfromtxt(pth) dstart.append(v.copy()) @@ -461,62 +433,22 @@ def eval_comp(sim): sim.success = True print(" " + msg) - return - - -# - No need to change any code below - +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6( - Simulation( - dir, +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_comp, htol=htol[idx], mf6_regression=True, - ) + ), + str(function_tmpdir), ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, - exfunc=eval_comp, - mf6_regression=True, - htol=htol[idx], - ) - test.run_mf6(sim) - - return - - -# use python test_gwf_csub_sub03.py --mf2005 mf2005devdbl -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_csub_subwt01.py b/autotest/test_gwf_csub_subwt01.py index b4fb615e35c..aad1e15e503 100644 --- a/autotest/test_gwf_csub_subwt01.py +++ b/autotest/test_gwf_csub_subwt01.py @@ -1,51 +1,21 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["csub_subwt01a", "csub_subwt01b", "csub_subwt01c", "csub_subwt01d"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" -cmppth = "mf6-regression" - +cmppth = "mf6_regression" htol = [None for n in ex] dtol = 1e-3 budtol = 1e-2 - paktest = "csub" - ump = [None, True, None, True] ivoid = [0, 1, 0, 1] gs0 = [0.0, 0.0, 1700.0, 1700.0] -# set travis to True when version 1.13.0 is released -continuous_integration = [True for n in ex] - -# set replace_exe to None to use default executable -replace_exe = None - # temporal discretization nper = 3 perlen = [1.0, 21915.0, 21915.0] @@ -432,67 +402,22 @@ def cbc_compare(sim): sim.success = True print(" " + msg) - return - - -# - No need to change any code below - +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6( - Simulation( - dir, - exe_dict=r_exe, +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_comp, htol=htol[idx], mf6_regression=True, - ) + ), + str(function_tmpdir), ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for dir in exdirs: - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, - exe_dict=replace_exe, - exfunc=eval_comp, - htol=htol[idx], - mf6_regression=True, - ) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_csub_subwt02.py b/autotest/test_gwf_csub_subwt02.py index 399390f0bdb..bf9068e4172 100644 --- a/autotest/test_gwf_csub_subwt02.py +++ b/autotest/test_gwf_csub_subwt02.py @@ -1,53 +1,25 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from conftest import project_root_path +from framework import TestFramework +from simulation import TestSimulation ex = ["csub_subwt02a", "csub_subwt02b", "csub_subwt02c", "csub_subwt02d"] timeseries = [True, False, True, False] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" -cmppth = "mf6-regression" - +cmppth = "mf6_regression" htol = [None, None, None, None] dtol = 1e-3 budtol = 1e-2 - paktest = "csub" - ump = [None, True, None, True] ivoid = [0, 1, 0, 1] gs0 = [0.0, 0.0, 1700.0, 1700.0] -# set travis to True when version 1.13.0 is released -continuous_integration = [True, True, True, True] - -# set replace_exe to None to use default executable -replace_exe = None - # static model data -pth = os.path.join(ddir, "ibc01_ibound.ref") +pth = str(project_root_path / "autotest" / "data" / "ibc01_ibound.ref") ib0 = np.genfromtxt(pth) # temporal discretization @@ -598,67 +570,22 @@ def cbc_compare(sim): sim.success = True print(" " + msg) - return - - -# - No need to change any code below - +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6( - Simulation( - dir, - exe_dict=r_exe, +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_comp, htol=htol[idx], mf6_regression=True, - ) + ), + str(function_tmpdir), ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for dir in exdirs: - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, - exe_dict=replace_exe, - exfunc=eval_comp, - htol=htol[idx], - mf6_regression=True, - ) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_csub_subwt03.py b/autotest/test_gwf_csub_subwt03.py index 85649fa11fa..abe743ca558 100644 --- a/autotest/test_gwf_csub_subwt03.py +++ b/autotest/test_gwf_csub_subwt03.py @@ -1,53 +1,25 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from conftest import project_root_path +from framework import TestFramework +from simulation import TestSimulation ex = ["csub_subwt03a", "csub_subwt03b", "csub_subwt03c", "csub_subwt03d"] nex = len(ex) -exdirs = [os.path.join("temp", s) for s in ex] - -ddir = "data" cmppth = "mf6" - htol = None # 0.1 dtol = 1e-3 budtol = 1e-2 - paktest = "csub" - isnewton = 2 * [None, "NEWTON"] headbased = [True, True, False, False] delay = 4 * [False] -# set travis to True when version 1.13.0 is released -continuous_integration = [True for s in ex] - -# set replace_exe to None to use default executable -replace_exe = None - # static model data -pth = os.path.join(ddir, "ibc01_ibound.ref") +pth = str(project_root_path / "autotest" / "data" / "ibc01_ibound.ref") ib0 = np.genfromtxt(pth) # temporal discretization @@ -440,8 +412,6 @@ def eval_comp(sim): # compare budgets cbc_compare(sim) - return - # compare cbc and lst budgets def cbc_compare(sim): @@ -538,64 +508,23 @@ def cbc_compare(sim): sim.success = True print(" " + msg) - return - - -# - No need to change any code below - +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6( - Simulation( - dir, exe_dict=r_exe, exfunc=eval_comp, cmp_verbose=False, htol=htol - ) - ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for dir in exdirs: - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, - exe_dict=replace_exe, +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_comp, cmp_verbose=False, htol=htol, - ) - test.run_mf6(sim) - - return - - -# use python testmf6_csub_subwt03.py -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() + ), + ws, + ) diff --git a/autotest/test_gwf_csub_wc01.py b/autotest/test_gwf_csub_wc01.py index de266afaade..1ec2bd2d69f 100644 --- a/autotest/test_gwf_csub_wc01.py +++ b/autotest/test_gwf_csub_wc01.py @@ -1,49 +1,21 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from conftest import project_root_path +from framework import TestFramework +from simulation import TestSimulation ex = ["csub_wc01a", "csub_wc02b"] -exdirs = [os.path.join("temp", s) for s in ex] - -ddir = "data" cmppth = "mf6" - dtol = 1e-3 budtol = 1e-2 - paktest = "csub" - isnewton = [None, "NEWTON"] -# set travis to True when version 1.13.0 is released -continuous_integration = [True for s in ex] - -# set replace_exe to None to use default executable -replace_exe = None - # static model data -pth = os.path.join(ddir, "ibc01_ibound.ref") +pth = str(project_root_path / "autotest" / "data" / "ibc01_ibound.ref") ib0 = np.genfromtxt(pth) # temporal discretization @@ -531,51 +503,15 @@ def cbc_compare(sim): print(" " + msg) -# - No need to change any code below - - +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6(Simulation(dir, exe_dict=r_exe, exfunc=eval_wcomp)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for dir in exdirs: - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exe_dict=replace_exe, exfunc=eval_wcomp) - test.run_mf6(sim) - - return - - -# main -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation(name=name, exe_dict=targets, exfunc=eval_wcomp), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_csub_wtgeo.py b/autotest/test_gwf_csub_wtgeo.py index be59a6d0535..6f691516290 100644 --- a/autotest/test_gwf_csub_wtgeo.py +++ b/autotest/test_gwf_csub_wtgeo.py @@ -1,26 +1,10 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = [ "csub_wtgeoa", @@ -31,31 +15,19 @@ "csub_wtgeof", "csub_wtgeog", ] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -constantcv = [True for idx in range(len(exdirs))] - -cmppth = "mf6-regression" -compare = [True for idx in range(len(exdirs))] +constantcv = [True for idx in range(len(ex))] +cmppth = "mf6_regression" +compare = [True for idx in range(len(ex))] tops = [0.0, 0.0, 150.0, 0.0, 0.0, 150.0, 150.0] ump = [None, None, True, None, True, None, True] iump = [0, 0, 1, 0, 1, 0, 1] -eslag = [True for idx in range(len(exdirs) - 2)] + 2 * [False] +eslag = [True for idx in range(len(ex) - 2)] + 2 * [False] # eslag = [True, True, True, False, True, False, False] headformulation = [True, False, False, True, True, False, False] ndc = [None, None, None, 19, 19, 19, 19] delay = [False, False, False, True, True, True, True] # newton = ["", "", "", "", "", None, ""] -newton = ["NEWTON" for idx in range(len(exdirs))] - -ddir = "data" - -## run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None +newton = ["NEWTON" for idx in range(len(ex))] htol = [None, None, None, 0.2, None, None, None] dtol = 1e-3 @@ -501,15 +473,8 @@ def get_model(idx, ws): def build_model(idx, dir): - - # build MODFLOW 6 files - ws = dir - sim = get_model(idx, ws) - - # build comparision files - ws = os.path.join(dir, cmppth) - mc = get_model(idx, ws) - + sim = get_model(idx, dir) # modflow6 files + mc = get_model(idx, os.path.join(dir, cmppth)) # build comparison files return sim, mc @@ -568,7 +533,6 @@ def eval_comp(sim): return -# compare cbc and lst budgets def cbc_compare(sim): print("evaluating cbc and budget...") # open cbc file @@ -663,71 +627,21 @@ def cbc_compare(sim): sim.success = True print(" " + msg) - return - - -# - No need to change any code below - -@pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), -) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6( - Simulation( - dir, +@pytest.mark.slow +@pytest.mark.parametrize("idx, name", list(enumerate(ex))) +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_comp, - exe_dict=r_exe, htol=htol[idx], idxsim=idx, mf6_regression=True, - ) + ), + ws, ) - - return - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, - exfunc=eval_comp, - exe_dict=replace_exe, - htol=htol[idx], - idxsim=idx, - mf6_regression=True, - ) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_csub_zdisp01.py b/autotest/test_gwf_csub_zdisp01.py index d5ac7645d3b..f6ee90544e8 100644 --- a/autotest/test_gwf_csub_zdisp01.py +++ b/autotest/test_gwf_csub_zdisp01.py @@ -1,46 +1,17 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from flopy.utils.compare import compare_heads +from framework import TestFramework +from simulation import TestSimulation ex = ["csub_zdisp01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - cmppth = "mfnwt" - -ddir = "data" - -## run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None - -htol = [None for idx in range(len(exdirs))] +htol = [None for idx in range(len(ex))] dtol = 1e-3 budtol = 1e-2 - bud_lst = [ "STO-SS_IN", "STO-SS_OUT", @@ -421,15 +392,11 @@ def get_model(idx, dir): backflag=0, idroptol=0, ) - return sim, mc + sim.write_simulation() + mc.write_input() -def build_models(): - for idx, dir in enumerate(exdirs): - sim, mc = get_model(idx, dir) - sim.write_simulation() - mc.write_input() - return + return sim, mc def eval_zdisplacement(sim): @@ -561,7 +528,7 @@ def eval_zdisplacement(sim): sim.simpath, f"{os.path.basename(sim.name)}.z-displacement.bin.out", ) - success_tst = pymake.compare_heads( + success_tst = compare_heads( None, None, text=text1, @@ -581,66 +548,22 @@ def eval_zdisplacement(sim): sim.success = False assert success_tst, msg - return - -# - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - build_models() - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6( - Simulation( - dir, +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + sim, mc = get_model(idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_zdisplacement, - exe_dict=r_exe, htol=htol[idx], idxsim=idx, - ) + ), + str(function_tmpdir), ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - build_models() - - # run the test model - for idx, dir in enumerate(exdirs): - sim = Simulation( - dir, - exfunc=eval_zdisplacement, - exe_dict=replace_exe, - htol=htol[idx], - idxsim=idx, - ) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_disu01.py b/autotest/test_gwf_disu.py similarity index 61% rename from autotest/test_gwf_disu01.py rename to autotest/test_gwf_disu.py index 6adc1d59f77..85880b95d82 100644 --- a/autotest/test_gwf_disu01.py +++ b/autotest/test_gwf_disu.py @@ -1,54 +1,13 @@ -""" -MODFLOW 6 Autotest -Test to make sure that disu is working correctly - -""" - import os -import shutil -import subprocess +import flopy import numpy as np +from flopy.utils.gridutil import get_disu_kwargs -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -import targets -from framework import set_teardown_test - -mf6_exe = os.path.abspath(targets.target_dict["mf6"]) -testname = "gwf_disu01" -testdir = os.path.join("temp", testname) -everything_was_successful = True - -teardown_test = set_teardown_test() - - -def run_mf6(argv, ws): - buff = [] - proc = subprocess.Popen( - argv, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=ws - ) - result, error = proc.communicate() - if result is not None: - c = result.decode("utf-8") - c = c.rstrip("\r\n") - print(f"{c}") - buff.append(c) - - return proc.returncode, buff - - -def test_disu_simple(): - from disu_util import get_disu_kwargs +def test_disu_simple(tmpdir, targets): + mf6 = targets["mf6"] name = "disu01a" - ws = f"{testdir}_{name}" nlay = 3 nrow = 3 ncol = 3 @@ -58,7 +17,7 @@ def test_disu_simple(): botm = [-10, -20, -30] disukwargs = get_disu_kwargs(nlay, nrow, ncol, delr, delc, top, botm) sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name=mf6_exe, sim_ws=ws + sim_name=name, version="mf6", exe_name=mf6, sim_ws=str(tmpdir) ) tdis = flopy.mf6.ModflowTdis(sim) gwf = flopy.mf6.ModflowGwf(sim, modelname=name) @@ -70,16 +29,11 @@ def test_disu_simple(): chd = flopy.mf6.modflow.mfgwfchd.ModflowGwfchd(gwf, stress_period_data=spd) sim.write_simulation() sim.run_simulation() - if teardown_test: - shutil.rmtree(ws, ignore_errors=True) - return - -def test_disu_idomain_simple(): - from disu_util import get_disu_kwargs +def test_disu_idomain_simple(tmpdir, targets): + mf6 = targets["mf6"] name = "disu01b" - ws = f"{testdir}_{name}" nlay = 3 nrow = 3 ncol = 3 @@ -92,7 +46,7 @@ def test_disu_idomain_simple(): disukwargs = get_disu_kwargs(nlay, nrow, ncol, delr, delc, top, botm) disukwargs["idomain"] = idomain sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name=mf6_exe, sim_ws=ws + sim_name=name, version="mf6", exe_name=mf6, sim_ws=str(tmpdir) ) tdis = flopy.mf6.ModflowTdis(sim) gwf = flopy.mf6.ModflowGwf(sim, modelname=name, save_flows=True) @@ -112,7 +66,7 @@ def test_disu_idomain_simple(): sim.run_simulation() # check binary grid file - fname = os.path.join(ws, name + ".disu.grb") + fname = os.path.join(str(tmpdir), name + ".disu.grb") grbobj = flopy.mf6.utils.MfGrdFile(fname) nodes = grbobj._datadict["NODES"] ia = grbobj._datadict["IA"] @@ -125,24 +79,13 @@ def test_disu_idomain_simple(): assert ja.shape[0] == 126, "ja should have size of 126" # load head array and ensure nodata value in second cell - fname = os.path.join(ws, name + ".hds") + fname = os.path.join(str(tmpdir), name + ".hds") hdsobj = flopy.utils.HeadFile(fname) head = hdsobj.get_alldata().flatten() assert head[1] == 1.0e30 # load flowja to make sure it is the right size - fname = os.path.join(ws, name + ".bud") + fname = os.path.join(str(tmpdir), name + ".bud") budobj = flopy.utils.CellBudgetFile(fname, precision="double") flowja = budobj.get_data(text="FLOW-JA-FACE")[0].flatten() assert flowja.shape[0] == 126 - if teardown_test: - shutil.rmtree(ws, ignore_errors=True) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - test_disu_simple() - test_disu_idomain_simple() diff --git a/autotest/test_gwf_disv_uzf.py b/autotest/test_gwf_disv_uzf.py index a4dcd4d8be1..cf89372267d 100644 --- a/autotest/test_gwf_disv_uzf.py +++ b/autotest/test_gwf_disv_uzf.py @@ -9,29 +9,15 @@ """ import os -import pytest -import sys -import numpy as np - -try: - import flopy - import flopy.utils.cvfdutil -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - - -from framework import testing_framework -from simulation import Simulation +import flopy +import flopy.utils.cvfdutil +import numpy as np +import pytest +from framework import TestFramework +from simulation import TestSimulation ex = ["disv_with_uzf"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - nlay = 5 nper = 5 perlen = [10] * 5 @@ -39,10 +25,8 @@ tsmult = len(perlen) * [1.0] botm = [20.0, 15.0, 10.0, 5.0, 0.0] strt = 20 - nouter, ninner = 100, 300 hclose, rclose, relax = 1e-9, 1e-3, 0.97 - ghb_ids = [] @@ -332,18 +316,14 @@ def build_model(idx, dir): def eval_model(sim): print("evaluating model...") - idx = sim.idxsim - name = ex[idx] - ws = os.path.join("temp", name) - # Next, get the binary printed heads - fpth = os.path.join(ws, name + ".hds") + fpth = os.path.join(sim.simpath, sim.name + ".hds") hobj = flopy.utils.HeadFile(fpth, precision="double") hds = hobj.get_alldata() hds = hds.reshape((np.sum(nstp), 5, 10, 10)) # Get the MF6 cell-by-cell fluxes - bpth = os.path.join(ws, name + ".cbc") + bpth = os.path.join(sim.simpath, sim.name + ".cbc") bobj = flopy.utils.CellBudgetFile(bpth, precision="double") bobj.get_unique_record_names() # ' STO-SS' @@ -361,7 +341,7 @@ def eval_model(sim): gwet = gwetv.reshape((np.sum(nstp), 5, 10, 10)) # Also retrieve the binary UZET output - uzpth = os.path.join(ws, name + ".uzf.bud") + uzpth = os.path.join(sim.simpath, sim.name + ".uzf.bud") uzobj = flopy.utils.CellBudgetFile(uzpth, precision="double") uzobj.get_unique_record_names() # b' FLOW-JA-FACE', @@ -473,36 +453,14 @@ def eval_model(sim): print("Finished running checks") -# - No need to change any code below -@pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), -) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print("standalone run of {}".format(os.path.basename(__file__))) - - # run main routine - main() +@pytest.mark.slow +@pytest.mark.parametrize("name", ex) +def test_mf6model(name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, 0, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=0 + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_drn_ddrn01.py b/autotest/test_gwf_drn_ddrn01.py index 11a7ec66fa3..7814053e45c 100644 --- a/autotest/test_gwf_drn_ddrn01.py +++ b/autotest/test_gwf_drn_ddrn01.py @@ -1,44 +1,17 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation paktest = "drn" budtol = 1e-2 - ex = ["drn_ddrn01a", "drn_ddrn01b"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) ddir = "data" - newton = [False, True] -# run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None - # static model data # spatial discretization nlay, nrow, ncol = 1, 1, 100 @@ -218,54 +191,16 @@ def drain_smoothing(xdiff, xrange, newton=False): return f -# - No need to change any code below - - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6( - Simulation(dir, exfunc=eval_disch, exe_dict=r_exe, idxsim=idx) +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_disch, idxsim=idx + ), + str(function_tmpdir), ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, exfunc=eval_disch, exe_dict=replace_exe, idxsim=idx - ) - test.run_mf6(sim) - return - - -# use python testmf6_drn_ddrn01.py -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_drn_ddrn02.py b/autotest/test_gwf_drn_ddrn02.py index 1e1c61f9f01..6f4cca16c45 100644 --- a/autotest/test_gwf_drn_ddrn02.py +++ b/autotest/test_gwf_drn_ddrn02.py @@ -1,41 +1,14 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation paktest = "drn" budtol = 1e-2 - ex = ["drn_ddrn02a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - -# run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None # static model data # spatial discretization @@ -198,57 +171,20 @@ def eval_disch(sim): sim.success = True print(" " + msg) - return - - -# - No need to change any code below - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6( - Simulation(dir, exfunc=eval_disch, exe_dict=r_exe, idxsim=idx) +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=str(function_tmpdir), + exe_dict=targets, + exfunc=eval_disch, + idxsim=idx, + ), + str(function_tmpdir), ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, exfunc=eval_disch, exe_dict=replace_exe, idxsim=idx - ) - test.run_mf6(sim) - return - - -# use python testmf6_drn_ddrn01.py -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_errors.py b/autotest/test_gwf_errors.py index fe688406f16..c7ba06ea3b2 100644 --- a/autotest/test_gwf_errors.py +++ b/autotest/test_gwf_errors.py @@ -6,31 +6,12 @@ """ -import os -import shutil import subprocess +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -import targets -from framework import set_teardown_test - -mf6_exe = os.path.abspath(targets.target_dict["mf6"]) -testname = "gwf_errors" -testdir = os.path.join("temp", testname) -os.makedirs(testdir, exist_ok=True) -everything_was_successful = True - -teardown_test = set_teardown_test() +from flopy.utils.gridutil import get_disu_kwargs def run_mf6(argv, ws): @@ -48,11 +29,9 @@ def run_mf6(argv, ws): return proc.returncode, buff -def run_mf6_error(ws, err_str_list): - returncode, buff = run_mf6([mf6_exe], ws) +def run_mf6_error(ws, exe, err_str_list): + returncode, buff = run_mf6([exe], ws) msg = "mf terminated with error" - if teardown_test: - shutil.rmtree(ws, ignore_errors=True) if returncode != 0: if not isinstance(err_str_list, list): err_str_list = list(err_str_list) @@ -68,6 +47,7 @@ def run_mf6_error(ws, err_str_list): def get_minimal_gwf_simulation( ws, + exe, name="test", simkwargs=None, simnamefilekwargs=None, @@ -111,7 +91,7 @@ def get_minimal_gwf_simulation( 0: [[(0, 0, 0), 0], [(0, nr - 1, nc - 1), 1]] } sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name=mf6_exe, sim_ws=ws, **simkwargs + sim_name=name, version="mf6", exe_name=exe, sim_ws=ws, **simkwargs ) if simnamefilekwargs is not None: for k in simnamefilekwargs: @@ -129,47 +109,50 @@ def get_minimal_gwf_simulation( return sim -def test_simple_model_success(): +def test_simple_model_success(function_tmpdir, targets): + mf6 = targets.mf6 + # test a simple model to make sure it runs and terminates correctly - ws = f"{testdir}_sim0" - sim = get_minimal_gwf_simulation(ws) + sim = get_minimal_gwf_simulation(str(function_tmpdir), mf6) sim.write_simulation() - returncode, buff = run_mf6([mf6_exe], ws) + returncode, buff = run_mf6([mf6], str(function_tmpdir)) assert returncode == 0, "mf6 failed for simple model." final_message = "Normal termination of simulation." failure_message = f'mf6 did not terminate with "{final_message}"' assert final_message in buff[-1], failure_message - if teardown_test: - shutil.rmtree(ws, ignore_errors=True) - return -def test_empty_folder(): +def test_empty_folder(function_tmpdir, targets): + mf6 = targets.mf6 with pytest.raises(RuntimeError): # make sure mf6 fails when there is no simulation name file err_str = "mf6: mfsim.nam is not present in working directory." - run_mf6_error(testdir, err_str) + run_mf6_error(str(function_tmpdir), mf6, err_str) -def test_sim_errors(): +def test_sim_errors(function_tmpdir, targets): + mf6 = targets.mf6 + with pytest.raises(RuntimeError): # verify that the correct number of errors are reported - ws = f"{testdir}_sim1" chdkwargs = {} chdkwargs["stress_period_data"] = { 0: [[(0, 0, 0), 0.0] for i in range(10)] } - sim = get_minimal_gwf_simulation(ws, chdkwargs=chdkwargs) + sim = get_minimal_gwf_simulation( + str(function_tmpdir), exe=mf6, chdkwargs=chdkwargs + ) sim.write_simulation() err_str = ["1. Cell is already a constant head ((1,1,1))."] - run_mf6_error(ws, err_str) + run_mf6_error(str(function_tmpdir), mf6, err_str) -def test_sim_maxerrors(): +def test_sim_maxerrors(function_tmpdir, targets): + mf6 = targets.mf6 + with pytest.raises(RuntimeError): # verify that the maxerrors keyword gives the correct error output - ws = f"{testdir}_sim2" simnamefilekwargs = {} simnamefilekwargs["maxerrors"] = 5 chdkwargs = {} @@ -177,7 +160,10 @@ def test_sim_maxerrors(): 0: [[(0, 0, 0), 0.0] for i in range(10)] } sim = get_minimal_gwf_simulation( - ws, simnamefilekwargs=simnamefilekwargs, chdkwargs=chdkwargs + str(function_tmpdir), + exe=mf6, + simnamefilekwargs=simnamefilekwargs, + chdkwargs=chdkwargs, ) sim.write_simulation() err_str = [ @@ -186,14 +172,13 @@ def test_sim_maxerrors(): "UNIT ERROR REPORT:", "1. ERROR OCCURRED WHILE READING FILE 'test.chd'", ] - run_mf6_error(ws, err_str) + run_mf6_error(str(function_tmpdir), mf6, err_str) -def test_disu_errors(): - with pytest.raises(RuntimeError): - from disu_util import get_disu_kwargs +def test_disu_errors(function_tmpdir, targets): + mf6 = targets.mf6 - ws = f"{testdir}_sim3" + with pytest.raises(RuntimeError): disukwargs = get_disu_kwargs( 3, 3, 3, np.ones(3), np.ones(3), 0, [-1, -2, -3] ) @@ -202,7 +187,10 @@ def test_disu_errors(): top[9] = 2.0 bot[9] = 1.0 sim = get_minimal_gwf_simulation( - ws, disukwargs=disukwargs, chdkwargs={"stress_period_data": [[]]} + str(function_tmpdir), + exe=mf6, + disukwargs=disukwargs, + chdkwargs={"stress_period_data": [[]]}, ) sim.write_simulation() err_str = [ @@ -212,34 +200,41 @@ def test_disu_errors(): "UNIT ERROR REPORT:" "1. ERROR OCCURRED WHILE READING FILE './test.disu'", ] - run_mf6_error(ws, err_str) + run_mf6_error(str(function_tmpdir), mf6, err_str) + +def test_solver_fail(function_tmpdir, targets): + mf6 = targets.mf6 -def test_solver_fail(): with pytest.raises(RuntimeError): # test failed to converge - ws = f"{testdir}_sim4" imskwargs = {"inner_maximum": 1, "outer_maximum": 2} - sim = get_minimal_gwf_simulation(ws, imskwargs=imskwargs) + sim = get_minimal_gwf_simulation( + str(function_tmpdir), exe=mf6, imskwargs=imskwargs + ) sim.write_simulation() err_str = [ "Simulation convergence failure occurred 1 time(s).", "Premature termination of simulation.", ] - run_mf6_error(ws, err_str) + run_mf6_error(str(function_tmpdir), mf6, err_str) + +def test_fail_continue_success(function_tmpdir, targets): + mf6 = targets.mf6 -def test_fail_continue_success(): # test continue but failed to converge - ws = f"{testdir}_sim5" tdiskwargs = {"nper": 1, "perioddata": [(10.0, 10, 1.0)]} imskwargs = {"inner_maximum": 1, "outer_maximum": 2} sim = get_minimal_gwf_simulation( - ws, imskwargs=imskwargs, tdiskwargs=tdiskwargs + str(function_tmpdir), + exe=mf6, + imskwargs=imskwargs, + tdiskwargs=tdiskwargs, ) sim.name_file.continue_ = True sim.write_simulation() - returncode, buff = run_mf6([mf6_exe], ws) + returncode, buff = run_mf6([mf6], str(function_tmpdir)) assert returncode == 0, "mf6 failed for simple model." final_message = "Simulation convergence failure occurred 10 time(s)." @@ -249,21 +244,3 @@ def test_fail_continue_success(): final_message = "Normal termination of simulation." failure_message = f'mf6 did not terminate with "{final_message}"' assert final_message in buff[0], failure_message - - if teardown_test: - shutil.rmtree(ws, ignore_errors=True) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - test_empty_folder() - test_simple_model_success() - test_sim_errors() - test_sim_maxerrors() - test_disu_errors() - test_solver_fail() - test_fail_continue_success() diff --git a/autotest/test_gwf_evt01.py b/autotest/test_gwf_evt01.py index 0c435b49146..d90d6ccfed5 100644 --- a/autotest/test_gwf_evt01.py +++ b/autotest/test_gwf_evt01.py @@ -1,32 +1,12 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["evt01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -196,39 +176,17 @@ def eval_model(sim): msg = f"{kper} {h} {sim_evt_rate} {cal_evt_rate}" assert np.allclose(sim_evt_rate, cal_evt_rate), msg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=idx + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_evt02.py b/autotest/test_gwf_evt02.py index 65d013c5e4c..ad1191eb7cc 100644 --- a/autotest/test_gwf_evt02.py +++ b/autotest/test_gwf_evt02.py @@ -1,35 +1,15 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["evt02"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -def build_model(idx, dir): +def build_model(idx, dir, exe): nlay, nrow, ncol = 1, 1, 3 chdheads = list(np.linspace(1, 100)) @@ -53,7 +33,7 @@ def build_model(idx, dir): # build MODFLOW 6 files ws = dir sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws + sim_name=name, version="mf6", exe_name=exe, sim_ws=ws ) # create tdis package tdis = flopy.mf6.ModflowTdis( @@ -178,39 +158,18 @@ def eval_model(sim): fpth = os.path.join(sim.simpath, "evt02.cbc") assert os.path.isfile(fpth), "model did not run with nseg=1 in EVT input" - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + mf6 = targets["mf6"] + test.build(lambda i, w: build_model(i, w, mf6), idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=idx + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_henry_nr.py b/autotest/test_gwf_henry_nr.py index 73c800532f9..c072f3f2b58 100644 --- a/autotest/test_gwf_henry_nr.py +++ b/autotest/test_gwf_henry_nr.py @@ -5,27 +5,14 @@ # and DRNs alternate and move up and down along the boundary to represent # the effects of tides on the aquifer. -import os - +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - from conftest import should_compare -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwf_henrynr01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # global model variables nlay = 20 @@ -78,8 +65,7 @@ def sinfunc(a, b, c, d, x): return a * np.sin(b * (x - c)) + d -def build_model(idx, dir): - +def build_model(idx, dir, exe): ws = dir name = ex[idx] @@ -103,7 +89,7 @@ def build_model(idx, dir): # build MODFLOW 6 files sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws + sim_name=name, version="mf6", exe_name=exe, sim_ws=ws ) sim.name_file.continue_ = False @@ -246,24 +232,25 @@ def build_model(idx, dir): # - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir, targets): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6( - Simulation( - dir, +def test_mf6model(idx, name, function_tmpdir, targets): + name = "gwf-henry-nr" + comparisons = {name: ("6.2.1",)} + mf6 = targets["mf6"] + test = TestFramework() + test.build(lambda i, w: build_model(i, w, mf6), idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, + exe_dict=targets, idxsim=idx, mf6_regression=True, cmp_verbose=False, - make_comparison=should_compare("gwf_henry_nr", comparisons={"gwf_henry_nr": ("6.2.1",)}, executables=targets), - ) + make_comparison=should_compare(name, comparisons, targets), + ), + str(function_tmpdir), ) diff --git a/autotest/test_gwf_ifmod_buy.py b/autotest/test_gwf_ifmod_buy.py index 65aad010cd6..79be47060a0 100644 --- a/autotest/test_gwf_ifmod_buy.py +++ b/autotest/test_gwf_ifmod_buy.py @@ -1,18 +1,10 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation # General test for the interface model approach. # It compares the result of a single reference model @@ -37,9 +29,6 @@ # for convenience. Finally, the budget error is checked. ex = ["ifmod_buy01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # some global convenience...: # model names @@ -655,42 +644,17 @@ def compare_to_ref(sim): cumul_balance_error, mname ) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -@pytest.mark.developmode -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # run the test model - test.run_mf6(Simulation(exdir, exfunc=compare_to_ref, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - - sim = Simulation(exdir, exfunc=compare_to_ref, idxsim=idx) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=compare_to_ref, idxsim=idx + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_ifmod_mult_exg.py b/autotest/test_gwf_ifmod_mult_exg.py index c4740a8157d..f56269b32e4 100644 --- a/autotest/test_gwf_ifmod_mult_exg.py +++ b/autotest/test_gwf_ifmod_mult_exg.py @@ -23,27 +23,14 @@ """ import os +import flopy import numpy as np import pytest from flopy.utils.lgrutil import Lgr -from modflowapi import ModflowApi - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["ifmod_mult_exg"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - name_parent = "parent" name_child = "child" g_delr = 10.0 @@ -275,8 +262,6 @@ def build_model(idx, exdir): def eval_heads(sim): - name = ex[sim.idxsim] - fpth = os.path.join(sim.simpath, f"{name_parent}.hds") hds = flopy.utils.HeadFile(fpth) heads = hds.get_data() @@ -344,42 +329,17 @@ def exact(x): # assert maxdiff_child_south > maxdiff_child_north - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "name", + ex, ) -@pytest.mark.developmode -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # run the test model - test.run_mf6(Simulation(exdir, exfunc=eval_heads, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - - sim = Simulation(exdir, exfunc=eval_heads, idxsim=idx) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, 0, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_heads, idxsim=0 + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_ifmod_rewet.py b/autotest/test_gwf_ifmod_rewet.py index c51e816e4af..8a58945edd1 100644 --- a/autotest/test_gwf_ifmod_rewet.py +++ b/autotest/test_gwf_ifmod_rewet.py @@ -1,18 +1,10 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation # General test for the interface model approach. # It compares the result of a single reference model @@ -39,9 +31,6 @@ # solution for convenience. Finally, the budget error is checked. ex = ["ifmod_rewet01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # some global convenience...: # model names @@ -399,42 +388,17 @@ def compare_to_ref(sim): cumul_balance_error, mname ) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -@pytest.mark.developmode -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # run the test model - test.run_mf6(Simulation(exdir, exfunc=compare_to_ref, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - - sim = Simulation(exdir, exfunc=compare_to_ref, idxsim=idx) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=compare_to_ref, idxsim=idx + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_ifmod_vert.py b/autotest/test_gwf_ifmod_vert.py index ac1e10f0673..16fd838da27 100644 --- a/autotest/test_gwf_ifmod_vert.py +++ b/autotest/test_gwf_ifmod_vert.py @@ -32,26 +32,14 @@ """ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - from flopy.utils.lgrutil import Lgr - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["ifmod_vert"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) parent_name = "parent" child_name = "child" @@ -292,41 +280,17 @@ def eval_heads(sim): errmsg = f"min or max residual too large {res.min()} {res.max()}" assert np.allclose(res, 0.0, atol=1.0e-6), errmsg - return - @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -@pytest.mark.developmode -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # run the test model - test.run_mf6(Simulation(exdir, exfunc=eval_heads, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - - sim = Simulation(exdir, exfunc=eval_heads, idxsim=idx) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_heads, idxsim=idx + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_ifmod_xt3d01.py b/autotest/test_gwf_ifmod_xt3d01.py index dbbd2d74349..88bd8776ffe 100644 --- a/autotest/test_gwf_ifmod_xt3d01.py +++ b/autotest/test_gwf_ifmod_xt3d01.py @@ -1,20 +1,11 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - from flopy.utils.lgrutil import Lgr - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation # Test for the interface model approach, when running # with a GWF-GWF exchange and XT3D applied on it. @@ -41,9 +32,6 @@ # confirm that there is no budget error. ex = ["ifmod_xt3d01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # globally for convenience... useXT3D = True @@ -314,8 +302,6 @@ def qxqyqz(fname, nlay, nrow, ncol): def eval_heads(sim): print("comparing heads and spec. discharges to analytical result...") - name = ex[sim.idxsim] - fpth = os.path.join(sim.simpath, f"{parent_name}.hds") hds = flopy.utils.HeadFile(fpth) heads = hds.get_data() @@ -475,7 +461,7 @@ def exact(x): ), "exchange observations do not match parent exchange flows" assert np.allclose( obsvalues, -child_exchange_flows - ), "exchange observations do not match child exchange flows" + ), "exchange observations do not match chile exchange flows" # Read the lumped boundname observations values fpth = os.path.join(sim.simpath, "gwf_obs_boundnames.csv") @@ -487,41 +473,17 @@ def exact(x): obsvalues, [-50.0, 50.0, 0, 0.0] ), "boundname observations do not match expected results" - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # run the test model - test.run_mf6(Simulation(exdir, exfunc=eval_heads, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - - sim = Simulation(exdir, exfunc=eval_heads, idxsim=idx) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, 0, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_heads, idxsim=0 + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_ifmod_xt3d02.py b/autotest/test_gwf_ifmod_xt3d02.py index b1e9146fdec..6ab53f467ea 100644 --- a/autotest/test_gwf_ifmod_xt3d02.py +++ b/autotest/test_gwf_ifmod_xt3d02.py @@ -1,20 +1,10 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from flopy.utils.lgrutil import Lgr - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation # Test for the interface model approach. # It compares the result of a single, strongly anisotropic model @@ -42,10 +32,6 @@ # should be identical. Finally, the budget error is checked. ex = ["ifmod_xt3d02"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - # global convenience... mname_ref = "refmodel" mname_left = "leftmodel" @@ -423,41 +409,17 @@ def compare_to_ref(sim): cumul_balance_error, mname ) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # run the test model - test.run_mf6(Simulation(exdir, exfunc=compare_to_ref, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - - sim = Simulation(exdir, exfunc=compare_to_ref, idxsim=idx) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=compare_to_ref, idxsim=idx + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_ims_rcm_reorder.py b/autotest/test_gwf_ims_rcm_reorder.py index c4eca177504..b6b587e5b38 100644 --- a/autotest/test_gwf_ims_rcm_reorder.py +++ b/autotest/test_gwf_ims_rcm_reorder.py @@ -1,26 +1,13 @@ import os +import flopy import pytest - -from budget_file_compare import eval_bud_diff - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from flopy.utils.compare import eval_bud_diff +from framework import TestFramework +from simulation import TestSimulation paktest = "ims" - -ex = [ - "ims_rcm", -] -exdirs = [os.path.join("temp", s) for s in ex] +ex = ["ims_rcm"] # spatial discretization data nlay, nrow, ncol = 2, 5, 30 @@ -31,9 +18,8 @@ chd_left = 10.0 chd_right = 5.0 -# -def build_model(idx, ws): +def build_model(idx, ws): # static model data # temporal discretization nper = 1 @@ -135,20 +121,19 @@ def build_models(idx, base_ws): def eval_flows(sim): - idx = sim.idxsim - name = ex[idx] + name = sim.name print("evaluating flow results..." f"({name})") - fpth = os.path.join(exdirs[idx], f"{name}.dis.grb") + fpth = os.path.join(sim.simpath, f"{name}.dis.grb") ia = flopy.mf6.utils.MfGrdFile(fpth).ia - fpth = os.path.join(exdirs[idx], f"{name}.cbc") + fpth = os.path.join(sim.simpath, f"{name}.cbc") b0 = flopy.utils.CellBudgetFile(fpth, precision="double") - fpth = os.path.join(exdirs[idx], "mf6", f"{name}.cbc") + fpth = os.path.join(sim.simpath, "mf6", f"{name}.cbc") b1 = flopy.utils.CellBudgetFile(fpth, precision="double") - fpth = os.path.join(exdirs[idx], f"{name}.cbc.cmp.out") + fpth = os.path.join(sim.simpath, f"{name}.cbc.cmp.out") eval_bud_diff(fpth, b0, b1, ia=ia) # close the budget files @@ -156,48 +141,20 @@ def eval_flows(sim): b1.close() -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_models, idx, exdir) - - # run the test models - test.run_mf6( - Simulation( - exdir, +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_models, 0, ws) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_flows, - idxsim=idx, - ) + idxsim=0, + ), + ws, ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_models, idx, exdir) - - sim = Simulation( - exdir, - exfunc=eval_flows, - idxsim=idx, - ) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_lakobs01.py b/autotest/test_gwf_lakobs01.py index 8ff09c449c9..8cfc8ff2de9 100644 --- a/autotest/test_gwf_lakobs01.py +++ b/autotest/test_gwf_lakobs01.py @@ -9,28 +9,13 @@ import shutil import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -import targets -from framework import testing_framework -from simulation import Simulation - -mf6_exe = os.path.abspath(targets.target_dict["mf6"]) +from framework import TestFramework +from simulation import TestSimulation ex = "gwf_lakobs_01a" -exdir = os.path.join("temp", ex) - - -# store global gwf for subsequent plotting gwf = None @@ -42,7 +27,7 @@ def get_idomain(nlay, nrow, ncol, lakend): return idomain -def build_model(): +def build_model(dir, exe): lx = 300.0 lz = 45.0 nlay = 45 @@ -75,8 +60,8 @@ def build_model(): sim = flopy.mf6.MFSimulation( sim_name=name, version="mf6", - exe_name=mf6_exe, - sim_ws=exdir, + exe_name=exe, + sim_ws=dir, ) # create tdis package @@ -220,69 +205,14 @@ def build_model(): return sim -# - No need to change any code below -def test_mf6model(): - # initialize testing framework - test = testing_framework() - - # build the models - sim = build_model() - - # write model input - sim.write_simulation() - - # attempt to run model, should fail - sim.run_simulation() - - # ensure that the error msg is contained in the mfsim.lst file - f = open(os.path.join(exdir, "mfsim.lst"), "r") - lines = f.readlines() - error_count = 0 - expected_msg = False - for line in lines: - if "ID2 (iconn) is missing" in line: - expected_msg = True - error_count += 1 - - assert error_count == 1, ( - "error count = " + str(error_count) + "but should equal 1" - ) - - # fix the error and attempt to rerun model - orig_fl = os.path.join(exdir, ex + ".lak.obs") - new_fl = os.path.join(exdir, ex + ".lak.obs.new") - sr = open(orig_fl, "r") - sw = open(new_fl, "w") - - lines = sr.readlines() - error_free_line = " lak1 lak 1 1\n" - for line in lines: - if " lak " in line: - sw.write(error_free_line) - else: - sw.write(line) +def test_mf6model(function_tmpdir, targets): + mf6 = targets["mf6"] - sr.close() - sw.close() - - # delete original and replace with corrected lab obs input - os.remove(orig_fl) - os.rename(new_fl, orig_fl) - - # rerun the model, should be no errors - sim.run_simulation() - - shutil.rmtree(exdir, ignore_errors=True) - - return - - -def main(): # initialize testing framework - test = testing_framework() + test = TestFramework() # build the models - sim = build_model() + sim = build_model(str(function_tmpdir), mf6) # write model input sim.write_simulation() @@ -291,7 +221,7 @@ def main(): sim.run_simulation() # ensure that the error msg is contained in the mfsim.lst file - f = open(os.path.join(exdir, "mfsim.lst"), "r") + f = open(str(function_tmpdir / "mfsim.lst"), "r") lines = f.readlines() error_count = 0 expected_msg = False @@ -301,12 +231,12 @@ def main(): error_count += 1 assert error_count == 1, ( - "error count = " + str(error_count) + ", but should equal 1" + "error count = " + str(error_count) + "but should equal 1" ) # fix the error and attempt to rerun model - orig_fl = os.path.join(exdir, ex + ".lak.obs") - new_fl = os.path.join(exdir, ex + ".lak.obs.new") + orig_fl = str(function_tmpdir / (ex + ".lak.obs")) + new_fl = str(function_tmpdir / (ex + ".lak.obs.new")) sr = open(orig_fl, "r") sw = open(new_fl, "w") @@ -327,16 +257,3 @@ def main(): # rerun the model, should be no errors sim.run_simulation() - - # clean the working directory - shutil.rmtree(exdir, ignore_errors=True) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_libmf6_evt01.py b/autotest/test_gwf_libmf6_evt01.py index 7bf1f6349d0..b962f653f30 100644 --- a/autotest/test_gwf_libmf6_evt01.py +++ b/autotest/test_gwf_libmf6_evt01.py @@ -7,33 +7,14 @@ import os +import flopy import numpy as np import pytest +from framework import TestFramework from modflowapi import ModflowApi - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation, api_return +from simulation import TestSimulation ex = ["libgwf_evt01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # et variables et_max = 0.1 @@ -172,24 +153,23 @@ def head2et_wellrate(h): def api_func(exe, idx, model_ws=None): - success = False - name = ex[idx].upper() if model_ws is None: model_ws = "." + output_file_path = os.path.join(model_ws, "mfsim.stdout") try: mf6 = ModflowApi(exe, working_directory=model_ws) except Exception as e: print("Failed to load " + exe) print("with message: " + str(e)) - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # initialize the model try: mf6.initialize() except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # time loop current_time = mf6.get_current_time() @@ -252,7 +232,8 @@ def api_func(exe, idx, model_ws=None): break if not has_converged: - return api_return(success, model_ws) + print("model did not converge") + return False, open(output_file_path).readlines() # finalize time step mf6.finalize_solve() @@ -263,50 +244,26 @@ def api_func(exe, idx, model_ws=None): # increment counter idx += 1 + # cleanup try: mf6.finalize() - success = True except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() - # cleanup and return - return api_return(success, model_ws) + return True, open(output_file_path).readlines() -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, idxsim=idx, api_func=api_func)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, idxsim=idx, api_func=api_func) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, idxsim=idx, api_func=api_func + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_libmf6_ghb01.py b/autotest/test_gwf_libmf6_ghb01.py index 6cb729387ee..43e7ce239f5 100644 --- a/autotest/test_gwf_libmf6_ghb01.py +++ b/autotest/test_gwf_libmf6_ghb01.py @@ -8,34 +8,14 @@ """ import os +import flopy import numpy as np import pytest +from framework import TestFramework from modflowapi import ModflowApi - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation, api_return +from simulation import TestSimulation ex = ["libgwf_ghb01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - # temporal discretization nper = 10 @@ -203,24 +183,23 @@ def api_ghb_pak(hcof, rhs): def api_func(exe, idx, model_ws=None): - success = False - name = ex[idx].upper() if model_ws is None: model_ws = "." + output_file_path = os.path.join(model_ws, "mfsim.stdout") try: mf6 = ModflowApi(exe, working_directory=model_ws) except Exception as e: print("Failed to load " + exe) print("with message: " + str(e)) - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # initialize the model try: mf6.initialize() except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # time loop current_time = mf6.get_current_time() @@ -291,47 +270,23 @@ def api_func(exe, idx, model_ws=None): # cleanup try: mf6.finalize() - success = True except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # cleanup and return - return api_return(success, model_ws) + return True, open(output_file_path).readlines() -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, idxsim=idx, api_func=api_func)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, idxsim=idx, api_func=api_func) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, idxsim=idx, api_func=api_func + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_libmf6_ifmod01.py b/autotest/test_gwf_libmf6_ifmod01.py index 3f138e5dc20..8105f35f88d 100644 --- a/autotest/test_gwf_libmf6_ifmod01.py +++ b/autotest/test_gwf_libmf6_ifmod01.py @@ -14,33 +14,13 @@ """ import os -import numpy as np +import flopy import pytest +from framework import TestFramework from modflowapi import ModflowApi - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation, api_return +from simulation import TestSimulation ex = ["libgwf_ifmod01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # global convenience... name_left = "leftmodel" @@ -231,24 +211,22 @@ def build_model(idx, dir): def api_func(exe, idx, model_ws=None): - success = False - - name = ex[idx].upper() if model_ws is None: model_ws = "." + output_file_path = os.path.join(model_ws, "mfsim.stdout") try: mf6 = ModflowApi(exe, working_directory=model_ws) except Exception as e: print("Failed to load " + exe) print("with message: " + str(e)) - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # initialize the model try: mf6.initialize() except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # test the interface models check_interface_models(mf6) @@ -260,18 +238,17 @@ def api_func(exe, idx, model_ws=None): try: mf6.update() except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() current_time = mf6.get_current_time() # finish try: mf6.finalize() - success = True except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # cleanup and return - return api_return(success, model_ws) + return True, open(output_file_path).readlines() def check_interface_models(mf6): @@ -330,38 +307,17 @@ def check_interface_models(mf6): ), "AREA in interface model does not match" -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, idxsim=idx, api_func=api_func)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, idxsim=idx, api_func=api_func) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, idxsim=idx, api_func=api_func + ), + ws, + ) diff --git a/autotest/test_gwf_libmf6_ifmod02.py b/autotest/test_gwf_libmf6_ifmod02.py index d0a1826f2cd..63dec777796 100644 --- a/autotest/test_gwf_libmf6_ifmod02.py +++ b/autotest/test_gwf_libmf6_ifmod02.py @@ -38,33 +38,14 @@ """ import os +import flopy import numpy as np import pytest +from framework import TestFramework from modflowapi import ModflowApi - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation, api_return +from simulation import TestSimulation ex = ["libgwf_ifmod02"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # global convenience... name_tl = "topleft" @@ -324,24 +305,23 @@ def build_model(idx, dir): def api_func(exe, idx, model_ws=None): - success = False - - name = ex[idx].upper() if model_ws is None: model_ws = "." + output_file_path = os.path.join(model_ws, "mfsim.stdout") + try: mf6 = ModflowApi(exe, working_directory=model_ws) except Exception as e: print("Failed to load " + exe) print("with message: " + str(e)) - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # initialize the model try: mf6.initialize() except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # test the interface models check_interface_models(mf6) @@ -353,18 +333,17 @@ def api_func(exe, idx, model_ws=None): try: mf6.update() except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() current_time = mf6.get_current_time() # finish try: mf6.finalize() - success = True except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # cleanup and return - return api_return(success, model_ws) + return True, open(output_file_path).readlines() def check_interface_models(mf6): @@ -424,39 +403,16 @@ def check_interface_models(mf6): ) -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -@pytest.mark.developmode -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, idxsim=idx, api_func=api_func)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, idxsim=idx, api_func=api_func) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, idxsim=idx, api_func=api_func + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_libmf6_ifmod03.py b/autotest/test_gwf_libmf6_ifmod03.py index 003a03b2d8f..c238d269110 100644 --- a/autotest/test_gwf_libmf6_ifmod03.py +++ b/autotest/test_gwf_libmf6_ifmod03.py @@ -28,33 +28,14 @@ """ import os +import flopy import numpy as np import pytest +from framework import TestFramework from modflowapi import ModflowApi - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation, api_return +from simulation import TestSimulation ex = ["libgwf_ifmod03"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # global convenience... name_left = "left" @@ -241,24 +222,23 @@ def build_model(idx, dir): def api_func(exe, idx, model_ws=None): - success = False - - name = ex[idx].upper() if model_ws is None: model_ws = "." + output_file_path = os.path.join(model_ws, "mfsim.stdout") + try: mf6 = ModflowApi(exe, working_directory=model_ws) except Exception as e: print("Failed to load " + exe) print("with message: " + str(e)) - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # initialize the model try: mf6.initialize() except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # test the interface models check_interface_models(mf6) @@ -270,7 +250,7 @@ def api_func(exe, idx, model_ws=None): try: mf6.update() except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() current_time = mf6.get_current_time() # finish @@ -278,10 +258,10 @@ def api_func(exe, idx, model_ws=None): mf6.finalize() success = True except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # cleanup and return - return api_return(success, model_ws) + return True, open(output_file_path).readlines() def check_interface_models(mf6): @@ -309,38 +289,16 @@ def check_interface_models(mf6): assert abs(ymax - ymin) < 1e-6 -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, idxsim=idx, api_func=api_func)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, idxsim=idx, api_func=api_func) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, idxsim=idx, api_func=api_func + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_libmf6_rch01.py b/autotest/test_gwf_libmf6_rch01.py index 07592d15a94..bb8252e8cff 100644 --- a/autotest/test_gwf_libmf6_rch01.py +++ b/autotest/test_gwf_libmf6_rch01.py @@ -10,33 +10,14 @@ import os +import flopy import numpy as np import pytest +from framework import TestFramework from modflowapi import ModflowApi - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation, api_return +from simulation import TestSimulation ex = ["libgwf_rch01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # recharge package name rch_pname = "RCH-1" @@ -168,24 +149,24 @@ def build_model(idx, dir): def api_func(exe, idx, model_ws=None): - success = False - name = ex[idx].upper() if model_ws is None: model_ws = "." + output_file_path = os.path.join(model_ws, "mfsim.stdout") + try: mf6 = ModflowApi(exe, working_directory=model_ws) except Exception as e: print("Failed to load " + exe) print("with message: " + str(e)) - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # initialize the model try: mf6.initialize() except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # time loop current_time = mf6.get_current_time() @@ -229,7 +210,7 @@ def api_func(exe, idx, model_ws=None): break if not has_converged: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # finalize time step mf6.finalize_solve() @@ -244,47 +225,23 @@ def api_func(exe, idx, model_ws=None): # cleanup try: mf6.finalize() - success = True except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # cleanup and return - return api_return(success, model_ws) + return True, open(output_file_path).readlines() -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, idxsim=idx, api_func=api_func)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, idxsim=idx, api_func=api_func) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, idxsim=idx, api_func=api_func + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_libmf6_rch02.py b/autotest/test_gwf_libmf6_rch02.py index 3ed421c2254..1e7a5797a3e 100644 --- a/autotest/test_gwf_libmf6_rch02.py +++ b/autotest/test_gwf_libmf6_rch02.py @@ -7,33 +7,14 @@ import os +import flopy import numpy as np import pytest +from framework import TestFramework from modflowapi import ModflowApi - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation, api_return +from simulation import TestSimulation ex = ["libgwf_rch02"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # recharge package name rch_pname = "RCH-1" @@ -88,7 +69,7 @@ hclose, rclose, relax = 1e-9, 1e-3, 0.97 -def get_model(ws, name, rech=rch_spd): +def get_model(ws, name, exe, rech=rch_spd): sim = flopy.mf6.MFSimulation( sim_name=name, version="mf6", @@ -172,15 +153,15 @@ def get_model(ws, name, rech=rch_spd): return sim -def build_model(idx, dir): +def build_model(idx, dir, exe): # build MODFLOW 6 files ws = dir name = ex[idx] - sim = get_model(ws, name) + sim = get_model(ws, name, exe) # build comparison model ws = os.path.join(dir, "libmf6") - mc = get_model(ws, name, rech=0.0) + mc = get_model(ws, name, exe, rech=0.0) return sim, mc @@ -203,13 +184,14 @@ def run_perturbation(mf6, max_iter, recharge, tag, rch): def api_func(exe, idx, model_ws=None): print("\nBMI implementation test:") - success = False name = ex[idx].upper() init_wd = os.path.abspath(os.getcwd()) if model_ws is not None: os.chdir(model_ws) + output_file_path = os.path.join(model_ws, "mfsim.stdout") + # get the observations from the standard run fpth = os.path.join("..", f"{ex[idx]}.head.obs.csv") hobs = np.genfromtxt(fpth, delimiter=",", names=True)["H1_6_6"] @@ -219,13 +201,13 @@ def api_func(exe, idx, model_ws=None): except Exception as e: print("Failed to load " + exe) print("with message: " + str(e)) - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # initialize the model try: mf6.initialize() except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # time loop current_time = mf6.get_current_time() @@ -265,7 +247,7 @@ def api_func(exe, idx, model_ws=None): mf6, max_iter, new_recharge, rch_tag, rch ) if not has_converged: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() h0 = head.reshape((nrow, ncol))[5, 5] r0 = h0 - htarget @@ -274,7 +256,7 @@ def api_func(exe, idx, model_ws=None): mf6, max_iter, new_recharge, rch_tag, rch + drch ) if not has_converged: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() h1 = head.reshape((nrow, ncol))[5, 5] r1 = h1 - htarget @@ -302,7 +284,7 @@ def api_func(exe, idx, model_ws=None): mf6, max_iter, new_recharge, rch_tag, rch ) if not has_converged: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # finalize time step mf6.finalize_solve() @@ -316,50 +298,30 @@ def api_func(exe, idx, model_ws=None): # cleanup try: mf6.finalize() - success = True except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() if model_ws is not None: os.chdir(init_wd) # cleanup and return - return api_return(success, model_ws) + return True, open(output_file_path).readlines() -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, idxsim=idx, api_func=api_func)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, idxsim=idx, api_func=api_func) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build( + lambda i, d: build_model(i, d, targets["mf6"]), + idx, + str(function_tmpdir), + ) + test.run( + TestSimulation( + name=name, exe_dict=targets, idxsim=idx, api_func=api_func + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_libmf6_riv01.py b/autotest/test_gwf_libmf6_riv01.py index 7a753137e86..0fc8dd7e598 100644 --- a/autotest/test_gwf_libmf6_riv01.py +++ b/autotest/test_gwf_libmf6_riv01.py @@ -5,34 +5,14 @@ """ import os +import flopy import numpy as np import pytest +from framework import TestFramework from modflowapi import ModflowApi - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation, api_return +from simulation import TestSimulation ex = ["libgwf_riv01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - # temporal discretization nper = 10 @@ -174,24 +154,24 @@ def build_model(idx, dir): def api_func(exe, idx, model_ws=None): - success = False - name = ex[idx].upper() if model_ws is None: model_ws = "." + output_file_path = os.path.join(model_ws, "mfsim.stdout") + try: mf6 = ModflowApi(exe, working_directory=model_ws) except Exception as e: print("Failed to load " + exe) print("with message: " + str(e)) - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # initialize the model try: mf6.initialize() except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # time loop current_time = mf6.get_current_time() @@ -240,7 +220,7 @@ def api_func(exe, idx, model_ws=None): break if not has_converged: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # finalize time step mf6.finalize_solve() @@ -255,47 +235,23 @@ def api_func(exe, idx, model_ws=None): # cleanup try: mf6.finalize() - success = True except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # cleanup and return - return api_return(success, model_ws) + return True, open(output_file_path).readlines() -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, idxsim=idx, api_func=api_func)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, idxsim=idx, api_func=api_func) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, idxsim=idx, api_func=api_func + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_libmf6_riv02.py b/autotest/test_gwf_libmf6_riv02.py index 67d7f04fd20..eb3337c0561 100644 --- a/autotest/test_gwf_libmf6_riv02.py +++ b/autotest/test_gwf_libmf6_riv02.py @@ -5,34 +5,14 @@ """ import os +import flopy import numpy as np import pytest +from framework import TestFramework from modflowapi import ModflowApi - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation, api_return +from simulation import TestSimulation ex = ["libgwf_riv02"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - # temporal discretization nper = 10 @@ -188,24 +168,24 @@ def api_riv_pak(stage, h, hcof, rhs): def api_func(exe, idx, model_ws=None): - success = False - name = ex[idx].upper() if model_ws is None: model_ws = "." + output_file_path = os.path.join(model_ws, "mfsim.stdout") + try: mf6 = ModflowApi(exe, working_directory=model_ws) except Exception as e: print("Failed to load " + exe) print("with message: " + str(e)) - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # initialize the model try: mf6.initialize() except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # time loop current_time = mf6.get_current_time() @@ -287,45 +267,22 @@ def api_func(exe, idx, model_ws=None): mf6.finalize() success = True except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # cleanup and return - return api_return(success, model_ws) + return True, open(output_file_path).readlines() -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, idxsim=idx, api_func=api_func)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, idxsim=idx, api_func=api_func) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, idxsim=idx, api_func=api_func + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_libmf6_sto01.py b/autotest/test_gwf_libmf6_sto01.py index 80e4365cd59..4cbe8caeb68 100644 --- a/autotest/test_gwf_libmf6_sto01.py +++ b/autotest/test_gwf_libmf6_sto01.py @@ -7,33 +7,14 @@ import os +import flopy import numpy as np import pytest +from framework import TestFramework from modflowapi import ModflowApi - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation, api_return +from simulation import TestSimulation ex = ["libgwf_sto01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # average recharge rate avg_rch = 0.001 @@ -171,24 +152,24 @@ def build_model(idx, dir): def api_func(exe, idx, model_ws=None): - success = False - name = ex[idx].upper() if model_ws is None: model_ws = "." + output_file_path = os.path.join(model_ws, "mfsim.stdout") + try: mf6 = ModflowApi(exe, working_directory=model_ws) except Exception as e: print("Failed to load " + exe) print("with message: " + str(e)) - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # initialize the model try: mf6.initialize() except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # time loop current_time = mf6.get_current_time() @@ -209,7 +190,7 @@ def api_func(exe, idx, model_ws=None): try: mf6.update() except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # update time current_time = mf6.get_current_time() @@ -220,47 +201,24 @@ def api_func(exe, idx, model_ws=None): # cleanup try: mf6.finalize() - success = True except: - return api_return(success, model_ws) + return False, open(output_file_path).readlines() # cleanup and return - return api_return(success, model_ws) + return True, open(output_file_path).readlines() -# - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, idxsim=idx, api_func=api_func)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, idxsim=idx, api_func=api_func) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, exe_dict=targets, idxsim=idx, api_func=api_func + ), + str(function_tmpdir), + ) diff --git a/autotest/test_gwf_maw01.py b/autotest/test_gwf_maw01.py deleted file mode 100644 index 425388bf22f..00000000000 --- a/autotest/test_gwf_maw01.py +++ /dev/null @@ -1,252 +0,0 @@ -import os - -import numpy as np -import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -ex = ["maw01", "maw01nwt", "maw01nwtur"] -newtonoptions = [None, "NEWTON", "NEWTON UNDER_RELAXATION"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - - -def build_model(idx, dir): - - nlay, nrow, ncol = 1, 1, 3 - nper = 3 - perlen = [1.0, 1.0, 1.0] - nstp = [1, 1, 1] - tsmult = [1.0, 1.0, 1.0] - lenx = 300.0 - delr = delc = lenx / float(nrow) - strt = 100.0 - hnoflo = 1e30 - hdry = -1e30 - hk = 1.0 - - nouter, ninner = 100, 300 - hclose, rclose, relax = 1e-9, 1e-3, 1.0 - krylov = ["CG", "BICGSTAB", "BICGSTAB"] - - tdis_rc = [] - for i in range(nper): - tdis_rc.append((perlen[i], nstp[i], tsmult[i])) - - name = ex[idx] - - # build MODFLOW 6 files - ws = dir - sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws - ) - # create tdis package - tdis = flopy.mf6.ModflowTdis( - sim, time_units="DAYS", nper=nper, perioddata=tdis_rc - ) - - # create gwf model - gwf = flopy.mf6.MFModel( - sim, - model_type="gwf6", - modelname=name, - model_nam_file=f"{name}.nam", - ) - gwf.name_file.newtonoptions = newtonoptions[idx] - - # create iterative model solution and register the gwf model with it - ims = flopy.mf6.ModflowIms( - sim, - print_option="SUMMARY", - outer_dvclose=hclose, - outer_maximum=nouter, - under_relaxation="NONE", - inner_maximum=ninner, - inner_dvclose=hclose, - rcloserecord=rclose, - linear_acceleration=krylov[idx], - scaling_method="NONE", - reordering_method="NONE", - relaxation_factor=relax, - ) - sim.register_ims_package(ims, [gwf.name]) - - dis = flopy.mf6.ModflowGwfdis( - gwf, - nlay=nlay, - nrow=nrow, - ncol=ncol, - delr=delr, - delc=delc, - top=100.0, - botm=0.0, - idomain=1, - filename=f"{name}.dis", - ) - - # initial conditions - ic = flopy.mf6.ModflowGwfic(gwf, strt=strt, filename=f"{name}.ic") - - # node property flow - npf = flopy.mf6.ModflowGwfnpf( - gwf, - save_flows=True, - icelltype=1, - k=hk, - k33=hk, - filename=f"{name}.npf", - ) - # storage - sto = flopy.mf6.ModflowGwfsto( - gwf, - save_flows=True, - iconvert=1, - ss=0.0, - sy=0.1, - steady_state={0: True}, - # transient={1: False}, - filename=f"{name}.sto", - ) - - # chd files - chdlist0 = [] - chdlist0.append([(0, 0, 0), 100.0]) - chdlist0.append([(0, 0, 2), 100.0]) - - chdlist1 = [] - chdlist1.append([(0, 0, 0), 25.0]) - chdlist1.append([(0, 0, 2), 25.0]) - - chdspdict = {0: chdlist0, 1: chdlist1, 2: chdlist0} - chd = flopy.mf6.ModflowGwfchd( - gwf, - stress_period_data=chdspdict, - save_flows=False, - filename=f"{name}.chd", - ) - - # wel files - # wel = flopy.mf6.ModflowGwfwel(gwf, print_input=True, print_flows=True, - # maxbound=len(ws), - # periodrecarray=wd6, - # save_flows=False) - # MAW - opth = f"{name}.maw.obs" - wellbottom = 50.0 - wellrecarray = [[0, 0.1, wellbottom, 100.0, "THIEM", 1]] - wellconnectionsrecarray = [[0, 0, (0, 0, 1), 100.0, wellbottom, 1.0, 0.1]] - wellperiodrecarray = [[0, "rate", 0.0]] - mawo_dict = {} - mawo_dict["maw_obs.csv"] = [("mh1", "head", 1)] - maw = flopy.mf6.ModflowGwfmaw( - gwf, - filename=f"{name}.maw", - print_input=True, - print_head=True, - print_flows=True, - save_flows=True, - observations=mawo_dict, - packagedata=wellrecarray, - connectiondata=wellconnectionsrecarray, - perioddata=wellperiodrecarray, - ) - - # output control - oc = flopy.mf6.ModflowGwfoc( - gwf, - budget_filerecord=f"{name}.cbc", - head_filerecord=f"{name}.hds", - headprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")], - saverecord=[("HEAD", "ALL")], - printrecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], - filename=f"{name}.oc", - ) - - return sim, None - - -def eval_maw(sim): - print("evaluating MAW heads...") - - # MODFLOW 6 maw results - fpth = os.path.join(sim.simpath, "maw_obs.csv") - try: - tc = np.genfromtxt(fpth, names=True, delimiter=",") - except: - assert False, f'could not load data from "{fpth}"' - - # create known results array - tc0 = np.array([100.0, 25.0, 100.0]) - - # calculate maximum absolute error - diff = tc["MH1"] - tc0 - diffmax = np.abs(diff).max() - dtol = 1e-9 - msg = f"maximum absolute maw head difference ({diffmax}) " - - if diffmax > dtol: - sim.success = False - msg += f"exceeds {dtol}" - assert diffmax < dtol, msg - else: - sim.success = True - print(" " + msg) - - return - - -# - No need to change any code below -@pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), -) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_maw, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_maw, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_maw02.py b/autotest/test_gwf_maw02.py deleted file mode 100644 index 745264a71cd..00000000000 --- a/autotest/test_gwf_maw02.py +++ /dev/null @@ -1,357 +0,0 @@ -import os -import sys - -import numpy as np -import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -ex = ["maw02"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - -budtol = 1e-2 -bud_lst = ["GWF_IN", "GWF_OUT", "RATE_IN", "RATE_OUT"] - -# spatial and temporal data -nlay, nrow, ncol = 1, 1, 3 -shape3d = (nlay, nrow, ncol) -size3d = nlay * nrow * ncol -nper = 5 -perlen = nper * [1.0] -nstp = nper * [1] -tsmult = nper * [1.0] -steady = nper * [True] -lenx = 300.0 -delr = delc = lenx / float(nrow) -botm = [0.0] -strt = 100.0 -hnoflo = 1e30 -hdry = -1e30 -hk = 1.0 - -nouter, ninner = 100, 300 -hclose, rclose, relax = 1e-9, 1e-3, 1.0 -krylov = ["CG"] - -tdis_rc = [] -for i in range(nper): - tdis_rc.append((perlen[i], nstp[i], tsmult[i])) - - -def build_model(idx, dir): - - name = ex[idx] - - # build MODFLOW 6 files - ws = dir - sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws - ) - # create tdis package - tdis = flopy.mf6.ModflowTdis( - sim, time_units="DAYS", nper=nper, perioddata=tdis_rc - ) - - # create gwf model - gwf = flopy.mf6.MFModel( - sim, - model_type="gwf6", - modelname=name, - model_nam_file=f"{name}.nam", - ) - - # create iterative model solution and register the gwf model with it - ims = flopy.mf6.ModflowIms( - sim, - print_option="SUMMARY", - outer_dvclose=hclose, - outer_maximum=nouter, - under_relaxation="NONE", - inner_maximum=ninner, - inner_dvclose=hclose, - rcloserecord=rclose, - linear_acceleration=krylov[idx], - scaling_method="NONE", - reordering_method="NONE", - relaxation_factor=relax, - ) - sim.register_ims_package(ims, [gwf.name]) - - dis = flopy.mf6.ModflowGwfdis( - gwf, - nlay=nlay, - nrow=nrow, - ncol=ncol, - delr=delr, - delc=delc, - top=100.0, - botm=0.0, - idomain=1, - filename=f"{name}.dis", - ) - - # initial conditions - ic = flopy.mf6.ModflowGwfic(gwf, strt=strt, filename=f"{name}.ic") - - # node property flow - npf = flopy.mf6.ModflowGwfnpf( - gwf, - save_flows=True, - icelltype=1, - k=hk, - k33=hk, - filename=f"{name}.npf", - ) - # storage - sto = flopy.mf6.ModflowGwfsto( - gwf, - save_flows=True, - iconvert=1, - ss=0.0, - sy=0.1, - steady_state={0: True}, - # transient={1: False}, - filename=f"{name}.sto", - ) - - # chd files - chdlist0 = [] - chdlist0.append([(0, 0, 0), 100.0]) - chdlist0.append([(0, 0, 2), 100.0]) - - chdlist1 = [] - chdlist1.append([(0, 0, 0), 25.0]) - chdlist1.append([(0, 0, 2), 25.0]) - - chdspdict = {0: chdlist0, 1: chdlist1, 2: chdlist0} - chd = flopy.mf6.ModflowGwfchd( - gwf, - stress_period_data=chdspdict, - save_flows=False, - filename=f"{name}.chd", - ) - - # MAW - opth = f"{name}.maw.obs" - wellbottom = 0.0 - wellrecarray = [ - [0, 0.1, wellbottom, 100.0, "THIEM", 1], - [1, 0.1, wellbottom, 100.0, "THIEM", 1], - ] - wellconnectionsrecarray = [ - [0, 0, (0, 0, 1), 100.0, wellbottom, 1.0, 0.1], - [1, 0, (0, 0, 1), 100.0, wellbottom, 1.0, 0.1], - ] - wellperiodrecarray = { - 0: [ - [0, "rate", -20.0], - [0, "status", "inactive"], - [0, "rate_scaling", 1.0, 15.0], - [1, "rate", -30.0], - [1, "status", "inactive"], - [1, "rate_scaling", 5.0, 15.0], - ], - 1: [ - [0, "rate", -110.0], - [0, "status", "active"], - [1, "rate", -130.0], - [1, "status", "active"], - ], - 3: [[0, "status", "inactive"]], - 4: [[0, "status", "active"]], - } - mawo_dict = {} - mawo_dict["maw_obs.csv"] = [("mh1", "head", 1)] - maw = flopy.mf6.ModflowGwfmaw( - gwf, - filename=f"{name}.maw", - budget_filerecord=f"{name}.maw.cbc", - print_input=True, - print_head=True, - print_flows=True, - save_flows=True, - observations=mawo_dict, - packagedata=wellrecarray, - connectiondata=wellconnectionsrecarray, - perioddata=wellperiodrecarray, - pname="MAW-1", - ) - - # output control - oc = flopy.mf6.ModflowGwfoc( - gwf, - budget_filerecord=f"{name}.cbc", - head_filerecord=f"{name}.hds", - headprintrecord=[("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL")], - saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], - printrecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], - filename=f"{name}.oc", - ) - - return sim, None - - -def eval_maw(sim): - print("evaluating MAW budgets...") - - # get results from listing file - fpth = os.path.join(sim.simpath, f"{os.path.basename(sim.name)}.lst") - budl = flopy.utils.Mf6ListBudget( - fpth, budgetkey="MAW-1 BUDGET FOR ENTIRE MODEL AT END OF TIME STEP" - ) - names = list(bud_lst) - d0 = budl.get_budget(names=names)[0] - dtype = d0.dtype - nbud = d0.shape[0] - - # get results from cbc file - cbc_bud = ["GWF", "RATE"] - d = np.recarray(nbud, dtype=dtype) - for key in bud_lst: - d[key] = 0.0 - fpth = os.path.join(sim.simpath, f"{os.path.basename(sim.name)}.maw.cbc") - cobj = flopy.utils.CellBudgetFile(fpth, precision="double") - kk = cobj.get_kstpkper() - times = cobj.get_times() - cbc_vals = [] - for idx, (k, t) in enumerate(zip(kk, times)): - for text in cbc_bud: - qin = 0.0 - qout = 0.0 - v = cobj.get_data(kstpkper=k, text=text)[0] - if isinstance(v, np.recarray): - vt = np.zeros(size3d, dtype=float) - wq = [] - for jdx, node in enumerate(v["node"]): - vt[node - 1] += v["q"][jdx] - wq.append(v["q"][jdx]) - v = vt.reshape(shape3d) - if text == cbc_bud[-1]: - cbc_vals.append(wq) - for kk in range(v.shape[0]): - for ii in range(v.shape[1]): - for jj in range(v.shape[2]): - vv = v[kk, ii, jj] - if vv < 0.0: - qout -= vv - else: - qin += vv - d["totim"][idx] = t - d["time_step"][idx] = k[0] - d["stress_period"] = k[1] - key = f"{text}_IN" - d[key][idx] = qin - key = f"{text}_OUT" - d[key][idx] = qout - - maw_vals = [ - [0.000, 0.000], - [-106.11303563809453, -96.22598985147631], - [-110.000, -130.000], - [0.0, -130.000], - [-110.000, -130.000], - ] - - # evaluate if well rates in cbc file are equal to expected values - diffv = [] - for ovs, svs in zip(maw_vals, cbc_vals): - for ov, sv in zip(ovs, svs): - diffv.append(ov - sv) - diffv = np.abs(np.array(diffv)).max() - msg = f"\nmaximum absolute maw rate difference ({diffv})\n" - - # calculate difference between water budget items in the lst and cbc files - diff = np.zeros((nbud, len(bud_lst)), dtype=float) - for idx, key in enumerate(bud_lst): - diff[:, idx] = d0[key] - d[key] - diffmax = np.abs(diff).max() - msg += f"maximum absolute total-budget difference ({diffmax}) " - - # write summary - fpth = os.path.join( - sim.simpath, f"{os.path.basename(sim.name)}.bud.cmp.out" - ) - f = open(fpth, "w") - for i in range(diff.shape[0]): - if i == 0: - line = f"{'TIME':>10s}" - for idx, key in enumerate(bud_lst): - line += f"{key + '_LST':>25s}" - line += f"{key + '_CBC':>25s}" - line += f"{key + '_DIF':>25s}" - f.write(line + "\n") - line = f"{d['totim'][i]:10g}" - for idx, key in enumerate(bud_lst): - line += f"{d0[key][i]:25g}" - line += f"{d[key][i]:25g}" - line += f"{diff[i, idx]:25g}" - f.write(line + "\n") - f.close() - - if diffmax > budtol or diffv > budtol: - sim.success = False - msg += f"\n...exceeds {budtol}" - assert diffmax < budtol, msg - else: - sim.success = True - print(" " + msg) - - return - - -# - No need to change any code below -@pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), -) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_maw, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_maw, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_maw03.py b/autotest/test_gwf_maw03.py deleted file mode 100644 index 0ef3963d939..00000000000 --- a/autotest/test_gwf_maw03.py +++ /dev/null @@ -1,275 +0,0 @@ -""" -MODFLOW 6 Autotest -Test the MAW HEAD_LIMIT and RATE_SCALING options for injection wells. These -options were not originally supported in MODFLOW 6. They were added for -version 6.0.4. - -""" - -import os -import sys - -import numpy as np -import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -ex = ["maw03a", "maw03b", "maw03c"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - -# maw settings for runs a, b, and c -mawsetting_a = [ - (0, "rate", 2000.0), -] -mawsetting_b = [(0, "rate", 2000.0), (0, "head_limit", 0.4)] -mawsetting_c = [(0, "rate", 2000.0), (0, "rate_scaling", 0.0, 1.0)] -mawsettings = [mawsetting_a, mawsetting_b, mawsetting_c] - - -def build_model(idx, dir): - - nlay, nrow, ncol = 1, 101, 101 - nper = 1 - perlen = [1000.0] - nstp = [50] - tsmult = [1.2] - delr = delc = 142.0 - top = 0.0 - botm = [-1000.0] - strt = 0.0 - hk = 10.0 - - nouter, ninner = 100, 100 - hclose, rclose, relax = 1e-6, 1e-6, 1.0 - - tdis_rc = [] - for i in range(nper): - tdis_rc.append((perlen[i], nstp[i], tsmult[i])) - - name = ex[idx] - - # build MODFLOW 6 files - ws = dir - sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=ws) - - # create tdis package - tdis = flopy.mf6.ModflowTdis( - sim, time_units="DAYS", nper=nper, perioddata=tdis_rc - ) - - # create gwf model - gwf = flopy.mf6.MFModel( - sim, - model_type="gwf6", - modelname=name, - model_nam_file=f"{name}.nam", - ) - - # create iterative model solution and register the gwf model with it - ims = flopy.mf6.ModflowIms( - sim, - print_option="SUMMARY", - outer_dvclose=hclose, - outer_maximum=nouter, - under_relaxation="NONE", - inner_maximum=ninner, - inner_dvclose=hclose, - rcloserecord=rclose, - linear_acceleration="CG", - scaling_method="NONE", - reordering_method="NONE", - relaxation_factor=relax, - ) - sim.register_ims_package(ims, [gwf.name]) - - dis = flopy.mf6.ModflowGwfdis( - gwf, - nlay=nlay, - nrow=nrow, - ncol=ncol, - delr=delr, - delc=delc, - top=top, - botm=botm, - idomain=1, - filename=f"{name}.dis", - ) - - # initial conditions - ic = flopy.mf6.ModflowGwfic(gwf, strt=strt, filename=f"{name}.ic") - - # node property flow - npf = flopy.mf6.ModflowGwfnpf( - gwf, - save_flows=True, - icelltype=1, - k=hk, - k33=hk, - filename=f"{name}.npf", - ) - - # storage - sto = flopy.mf6.ModflowGwfsto( - gwf, - save_flows=True, - iconvert=0, - ss=1.0e-5, - sy=0.1, - steady_state={0: False}, - transient={0: True}, - filename=f"{name}.sto", - ) - - # MAW - opth = f"{name}.maw.obs" - wellbottom = -1000 - wellrecarray = [[0, 0.15, wellbottom, 0.0, "THIEM", 1]] - wellconnectionsrecarray = [[0, 0, (0, 50, 50), 0.0, wellbottom, 0.0, 0.0]] - wellperiodrecarray = mawsettings[idx] - mawo_dict = {} - mawo_dict[f"{name}.maw.obs.csv"] = [ - ("m1head", "head", (0,)), - ("m1rate", "rate", (0,)), - ] # is this index one-based? Not if in a tuple - maw = flopy.mf6.ModflowGwfmaw( - gwf, - filename=f"{name}.maw", - print_input=True, - print_head=True, - print_flows=True, - save_flows=True, - observations=mawo_dict, - packagedata=wellrecarray, - connectiondata=wellconnectionsrecarray, - perioddata=wellperiodrecarray, - ) - - # output control - oc = flopy.mf6.ModflowGwfoc( - gwf, - budget_filerecord=f"{name}.cbc", - head_filerecord=f"{name}.hds", - headprintrecord=[ - ("COLUMNS", ncol, "WIDTH", 15, "DIGITS", 6, "GENERAL") - ], - saverecord=[("HEAD", "ALL")], - printrecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], - filename=f"{name}.oc", - ) - - # head observations - obs_data0 = [("head_well_cell", "HEAD", (0, 0, 0))] - obs_recarray = {f"{name}.obs.csv": obs_data0} - obs = flopy.mf6.ModflowUtlobs( - gwf, - pname="head_obs", - filename=f"{name}.obs", - digits=15, - print_input=True, - continuous=obs_recarray, - ) - - return sim, None - - -def eval_maw(sim): - print("evaluating MAW heads...") - - # MODFLOW 6 maw results - idx = sim.idxsim - name = ex[idx] - fpth = os.path.join(sim.simpath, f"{name}.maw.obs.csv") - try: - tc = np.genfromtxt(fpth, names=True, delimiter=",") - except: - assert False, f'could not load data from "{fpth}"' - - if idx == 0: - - # M1RATE should be 2000. - msg = "The injection rate should be 2000. for all times" - assert tc["M1RATE"].min() == tc["M1RATE"].max() == 2000, msg - - elif idx == 1: - - # M1RATE should have a minimum value less than 200 and - # M1HEAD should not exceed 0.400001 - msg = ( - "Injection rate should fall below 200 and the head should not" - "exceed 0.4" - ) - assert tc["M1RATE"].min() < 200.0, msg - assert tc["M1HEAD"].max() < 0.400001, msg - - elif idx == 2: - - # M1RATE should have a minimum value less than 800 - # M1HEAD should not exceed 1.0. - msg = ( - "Min injection rate should be less than 800 and well " - "head should not exceed 1.0" - ) - assert tc["M1RATE"].min() < 800.0 and tc["M1HEAD"].max() < 1.0, msg - - else: - - assert False, f"Test error. idx {idx} not being tested." - - return - - -# - No need to change any code below -@pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), -) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_maw, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_maw, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_maw04.py b/autotest/test_gwf_maw04.py index 403fc8905e4..e77656f0c68 100644 --- a/autotest/test_gwf_maw04.py +++ b/autotest/test_gwf_maw04.py @@ -1,52 +1,10 @@ import os -import sys +from types import SimpleNamespace +import flopy import numpy as np -import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation - -ex = [ - "maw_iss305a", - "maw_iss305b", - "maw_iss305c", - "maw_iss305d", - "maw_iss305e", - "maw_iss305f", -] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" -cmppth = "mf2005" - -paktest = "maw" - -require_failure = [True for i in range(len(exdirs))] -require_failure[0] = False - -# set travis to True when version 1.13.0 is released -continuous_integration = [True for n in ex] - -# set replace_exe to None to use default executable -replace_exe = None +from modflow_devtools.case import Case +from pytest_cases import parametrize # temporal discretization nper = 2 @@ -64,6 +22,7 @@ common_ratio = 1.01 nhalf = int(0.5 * ncol) + 1 first_term = 0.5 * xlen / ((1 - common_ratio**nhalf) / (1 - common_ratio)) + delr = np.zeros((ncol), dtype=float) for n in range(nhalf): if n == 0: @@ -105,195 +64,235 @@ radius = 0.25 sradius0 = radius + 0.1 wellq = -100.0 -skin_mult = [0.1, 10.0, 1.0, 0.0, -1.0, 100.0] -condeqn = ["CUMULATIVE", "SKIN", "SKIN", "SKIN", "SPECIFIED", "CUMULATIVE"] -sradius = [sradius0, sradius0, sradius0, sradius0, sradius0, radius0 * 1.5] - -tdis_rc = [] -for idx in range(nper): - tdis_rc.append((perlen[idx], nstp[idx], tsmult[idx])) - +skin_mult = {"a": 0.1, "b": 10.0, "c": 1.0, "d": 0.0, "e": -1.0, "f": 100.0} +condeqn = { + "a": "CUMULATIVE", + "b": "SKIN", + "c": "SKIN", + "d": "SKIN", + "e": "SPECIFIED", + "f": "CUMULATIVE", +} +sradius = { + "a": sradius0, + "b": sradius0, + "c": sradius0, + "d": sradius0, + "e": sradius0, + "f": radius0 * 1.5, +} hclose, rclose = 1e-9, 1e-6 -def build_model(idx, dir): - name = ex[idx] - ws = dir - - # build MODFLOW 6 files - sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws - ) - # create tdis package - tdis = flopy.mf6.ModflowTdis( - sim, time_units="DAYS", nper=nper, perioddata=tdis_rc - ) - - # create iterative model solution - ims = flopy.mf6.ModflowIms( - sim, inner_dvclose=hclose, rcloserecord=rclose, outer_dvclose=hclose - ) - - # create gwf model - gwf = flopy.mf6.ModflowGwf(sim, modelname=name, save_flows=True) - - # discretization - dis = flopy.mf6.ModflowGwfdis( - gwf, - nlay=nlay, - nrow=nrow, - ncol=ncol, - delr=delr, - delc=delr, - top=top, - botm=botm, - ) - # initial conditions - ic = flopy.mf6.ModflowGwfic(gwf, strt=strt) - - # node property flow - npf = flopy.mf6.ModflowGwfnpf( - gwf, save_flows=False, icelltype=confined, k=hk - ) - # storage - sto = flopy.mf6.ModflowGwfsto( - gwf, - save_flows=False, - iconvert=confined, - ss=ss, - steady_state={0: True}, - transient={1: True}, - ) - # constant head - chd = flopy.mf6.ModflowGwfchd( - gwf, stress_period_data=chd_spd, save_flows=False - ) - # multi-aquifer well - hks = hk * skin_mult[idx] - mpd = [[0, radius, botm[-1], strt, condeqn[idx], 2]] - mcd = [ - [0, 0, (0, nhalf, nhalf), top, botm[0], hks, sradius[idx]], - [0, 1, (1, nhalf, nhalf), botm[0], botm[1], hks, sradius[idx]], +def well4(label): + hks = hk * skin_mult[label] + packagedata = [[0, radius, botm[-1], strt, condeqn[label], 2]] + connectiondata = [ + [0, 0, (0, nhalf, nhalf), top, botm[0], hks, sradius[label]], + [0, 1, (1, nhalf, nhalf), botm[0], botm[1], hks, sradius[label]], ] perioddata = {1: [[0, "RATE", wellq]]} - maw = flopy.mf6.ModflowGwfmaw( - gwf, + return SimpleNamespace( print_input=True, no_well_storage=True, - packagedata=mpd, - connectiondata=mcd, + packagedata=packagedata, + connectiondata=connectiondata, perioddata=perioddata, ) - # output control - oc = flopy.mf6.ModflowGwfoc( - gwf, - budget_filerecord=f"{name}.cbc", - head_filerecord=f"{name}.hds", - saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], - ) - # build MODFLOW-2005 files - if require_failure[idx]: - mc = None - else: - ws = os.path.join(dir, cmppth) - mc = flopy.modflow.Modflow(name, model_ws=ws, version=cmppth) - dis = flopy.modflow.ModflowDis( - mc, - nlay=nlay, - nrow=nrow, - ncol=ncol, - nper=nper, - perlen=perlen, - nstp=nstp, - tsmult=tsmult, - steady=steady, - delr=delr, - delc=delr, - top=top, - botm=botm, - ) - bas = flopy.modflow.ModflowBas(mc, strt=strt) - lpf = flopy.modflow.ModflowLpf( - mc, laytyp=confined, hk=hk, vka=hk, ss=ss, sy=0 - ) - chd = flopy.modflow.ModflowChd(mc, stress_period_data=chd5_spd) - # mnw2 - # empty mnw2 file to create recarrays - mnw2 = flopy.modflow.ModflowMnw2(mc) - node_data = mnw2.get_empty_node_data(2) - node_data["ztop"] = np.array([top, botm[0]]) - node_data["zbotm"] = np.array([botm[0], botm[1]]) - node_data["i"] = np.array([nhalf, nhalf]) - node_data["j"] = np.array([nhalf, nhalf]) - node_data["wellid"] = np.array(["well1", "well1"]) - node_data["losstype"] = np.array(["skin", "skin"]) - node_data["rw"] = np.array([radius, radius]) - node_data["rskin"] = np.array([sradius[idx], sradius[idx]]) - node_data["kskin"] = np.array([hks, hks]) - dtype = [("wellid", np.unicode_, 20), ("qdes", " dtol: + config.success = False + msg += f"exceeds {dtol}" + assert diffmax < dtol, msg + else: + config.success = True + print(" " + msg) + + case2 = Case( + name="maw02", + krylov="CG", + nlay=1, + nrow=1, + ncol=3, + nper=5, + delr=300, + delc=300, + perlen=5 * [1], + nstp=5 * [1], + tsmult=5 * [1], + well=well2, + strt=100, + hk=1, + nouter=100, + ninner=300, + hclose=1e-9, + rclose=1e-3, + relaxation_factor=1, + compare=False, + ) + cases2 = [case2] + + @parametrize(data=cases2, ids=[c.name for c in cases2]) + def case_2(self, function_tmpdir, targets, data): + name = data.name + ws = str(function_tmpdir) + sim = flopy.mf6.MFSimulation( + sim_name=name, version="mf6", exe_name=targets["mf6"], sim_ws=ws + ) + + # create tdis package + tdis_rc = [ + (data.perlen[i], data.nstp[i], data.tsmult[i]) + for i in range(data.nper) + ] + tdis = flopy.mf6.ModflowTdis( + sim, time_units="DAYS", nper=data.nper, perioddata=tdis_rc + ) + + # create gwf model + gwf = flopy.mf6.MFModel( + sim, + model_type="gwf6", + modelname=name, + model_nam_file=f"{name}.nam", + ) + + # create iterative model solution and register the gwf model with it + ims = flopy.mf6.ModflowIms( + sim, + print_option="SUMMARY", + outer_dvclose=data.hclose, + outer_maximum=data.nouter, + under_relaxation="NONE", + inner_maximum=data.ninner, + inner_dvclose=data.hclose, + rcloserecord=data.rclose, + linear_acceleration=data.krylov, + scaling_method="NONE", + reordering_method="NONE", + relaxation_factor=data.relaxation_factor, + ) + sim.register_ims_package(ims, [gwf.name]) + + dis = flopy.mf6.ModflowGwfdis( + gwf, + nlay=data.nlay, + nrow=data.nrow, + ncol=data.ncol, + delr=data.delr, + delc=data.delc, + top=100.0, + botm=0.0, + idomain=1, + filename=f"{name}.dis", + ) + + # initial conditions + ic = flopy.mf6.ModflowGwfic(gwf, strt=data.strt, filename=f"{name}.ic") + + # node property flow + npf = flopy.mf6.ModflowGwfnpf( + gwf, + save_flows=True, + icelltype=1, + k=data.hk, + k33=data.hk, + filename=f"{name}.npf", + ) + # storage + sto = flopy.mf6.ModflowGwfsto( + gwf, + save_flows=True, + iconvert=1, + ss=0.0, + sy=0.1, + steady_state={0: True}, + # transient={1: False}, + filename=f"{name}.sto", + ) + + # chd files + chdlist0 = [] + chdlist0.append([(0, 0, 0), 100.0]) + chdlist0.append([(0, 0, 2), 100.0]) + + chdlist1 = [] + chdlist1.append([(0, 0, 0), 25.0]) + chdlist1.append([(0, 0, 2), 25.0]) + + chdspdict = {0: chdlist0, 1: chdlist1, 2: chdlist0} + chd = flopy.mf6.ModflowGwfchd( + gwf, + stress_period_data=chdspdict, + save_flows=False, + filename=f"{name}.chd", + ) + + # MAW + maw = flopy.mf6.ModflowGwfmaw( + gwf, + filename=f"{name}.maw", + budget_filerecord=f"{name}.maw.cbc", + print_input=True, + print_head=True, + print_flows=True, + save_flows=True, + observations=data.well.observations, + packagedata=data.well.packagedata, + connectiondata=data.well.connectiondata, + perioddata=data.well.perioddata, + pname="MAW-1", + ) + + # output control + oc = flopy.mf6.ModflowGwfoc( + gwf, + budget_filerecord=f"{name}.cbc", + head_filerecord=f"{name}.hds", + headprintrecord=[ + ("COLUMNS", 10, "WIDTH", 15, "DIGITS", 6, "GENERAL") + ], + saverecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], + printrecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], + filename=f"{name}.oc", + ) + + return data, sim, None, self.eval_2 + + def eval_2(self, config, data): + print("evaluating MAW budgets...") + + shape3d = (data.nlay, data.nrow, data.ncol) + size3d = data.nlay * data.nrow * data.ncol + + # get results from listing file + fpth = os.path.join( + config.simpath, f"{os.path.basename(config.name)}.lst" + ) + budl = flopy.utils.Mf6ListBudget( + fpth, budgetkey="MAW-1 BUDGET FOR ENTIRE MODEL AT END OF TIME STEP" + ) + names = list(self.bud_lst) + d0 = budl.get_budget(names=names)[0] + dtype = d0.dtype + nbud = d0.shape[0] + + # get results from cbc file + cbc_bud = ["GWF", "RATE"] + d = np.recarray(nbud, dtype=dtype) + for key in self.bud_lst: + d[key] = 0.0 + fpth = os.path.join( + config.simpath, f"{os.path.basename(config.name)}.maw.cbc" + ) + cobj = flopy.utils.CellBudgetFile(fpth, precision="double") + kk = cobj.get_kstpkper() + times = cobj.get_times() + cbc_vals = [] + for idx, (k, t) in enumerate(zip(kk, times)): + for text in cbc_bud: + qin = 0.0 + qout = 0.0 + v = cobj.get_data(kstpkper=k, text=text)[0] + if isinstance(v, np.recarray): + vt = np.zeros(size3d, dtype=float) + wq = [] + for jdx, node in enumerate(v["node"]): + vt[node - 1] += v["q"][jdx] + wq.append(v["q"][jdx]) + v = vt.reshape(shape3d) + if text == cbc_bud[-1]: + cbc_vals.append(wq) + for kk in range(v.shape[0]): + for ii in range(v.shape[1]): + for jj in range(v.shape[2]): + vv = v[kk, ii, jj] + if vv < 0.0: + qout -= vv + else: + qin += vv + d["totim"][idx] = t + d["time_step"][idx] = k[0] + d["stress_period"] = k[1] + key = f"{text}_IN" + d[key][idx] = qin + key = f"{text}_OUT" + d[key][idx] = qout + + maw_vals = [ + [0.000, 0.000], + [-106.11303563809453, -96.22598985147631], + [-110.000, -130.000], + [0.0, -130.000], + [-110.000, -130.000], + ] + + # evaluate if well rates in cbc file are equal to expected values + diffv = [] + for ovs, svs in zip(maw_vals, cbc_vals): + for ov, sv in zip(ovs, svs): + diffv.append(ov - sv) + diffv = np.abs(np.array(diffv)).max() + msg = f"\nmaximum absolute maw rate difference ({diffv})\n" + + # calculate difference between water budget items in the lst and cbc files + diff = np.zeros((nbud, len(self.bud_lst)), dtype=float) + for idx, key in enumerate(self.bud_lst): + diff[:, idx] = d0[key] - d[key] + diffmax = np.abs(diff).max() + msg += f"maximum absolute total-budget difference ({diffmax}) " + + # write summary + fpth = os.path.join( + config.simpath, f"{os.path.basename(config.name)}.bud.cmp.out" + ) + f = open(fpth, "w") + for i in range(diff.shape[0]): + if i == 0: + line = f"{'TIME':>10s}" + for idx, key in enumerate(self.bud_lst): + line += f"{key + '_LST':>25s}" + line += f"{key + '_CBC':>25s}" + line += f"{key + '_DIF':>25s}" + f.write(line + "\n") + line = f"{d['totim'][i]:10g}" + for idx, key in enumerate(self.bud_lst): + line += f"{d0[key][i]:25g}" + line += f"{d[key][i]:25g}" + line += f"{diff[i, idx]:25g}" + f.write(line + "\n") + f.close() + + if diffmax > self.budtol or diffv > self.budtol: + config.success = False + msg += f"\n...exceeds {self.budtol}" + assert diffmax < self.budtol, msg + else: + config.success = True + print(" " + msg) + + case3 = Case( + name="maw03", + krylov="CG", + nlay=1, + nrow=101, + ncol=101, + nper=1, + delr=142, + delc=142, + perlen=[1000], + nstp=[50], + tsmult=[1.2], + strt=0, + hk=10, + nouter=100, + ninner=100, + hclose=1e-6, + rclose=1e-6, + relaxation_factor=1, + compare=False, + ) + cases3 = [ + case3.copy_update( + name="maw03a", + well=well3("maw03a"), + ), + case3.copy_update(name="maw03b", well=well3("maw03b")), + case3.copy_update(name="maw03c", well=well3("maw03c")), + ] + + @parametrize(data=cases3, ids=[c.name for c in cases3]) + def case_3(self, function_tmpdir, targets, data): + top = 0.0 + botm = [-1000.0] + + tdis_rc = [] + for i in range(data.nper): + tdis_rc.append((data.perlen[i], data.nstp[i], data.tsmult[i])) + + name = data.name + ws = str(function_tmpdir) + sim = flopy.mf6.MFSimulation( + sim_name=name, sim_ws=ws, exe_name=targets["mf6"] + ) + + # create tdis package + tdis = flopy.mf6.ModflowTdis( + sim, time_units="DAYS", nper=data.nper, perioddata=tdis_rc + ) + + # create gwf model + gwf = flopy.mf6.MFModel( + sim, + model_type="gwf6", + modelname=name, + model_nam_file=f"{name}.nam", + ) + + # create iterative model solution and register the gwf model with it + ims = flopy.mf6.ModflowIms( + sim, + print_option="SUMMARY", + outer_dvclose=data.hclose, + outer_maximum=data.nouter, + under_relaxation="NONE", + inner_maximum=data.ninner, + inner_dvclose=data.hclose, + rcloserecord=data.rclose, + linear_acceleration=data.krylov, + scaling_method="NONE", + reordering_method="NONE", + relaxation_factor=data.relaxation_factor, + ) + sim.register_ims_package(ims, [gwf.name]) + + dis = flopy.mf6.ModflowGwfdis( + gwf, + nlay=data.nlay, + nrow=data.nrow, + ncol=data.ncol, + delr=data.delr, + delc=data.delc, + top=top, + botm=botm, + idomain=1, + filename=f"{name}.dis", + ) + + # initial conditions + ic = flopy.mf6.ModflowGwfic(gwf, strt=data.strt, filename=f"{name}.ic") + + # node property flow + npf = flopy.mf6.ModflowGwfnpf( + gwf, + save_flows=True, + icelltype=1, + k=data.hk, + k33=data.hk, + filename=f"{name}.npf", + ) + + # storage + sto = flopy.mf6.ModflowGwfsto( + gwf, + save_flows=True, + iconvert=0, + ss=1.0e-5, + sy=0.1, + steady_state={0: False}, + transient={0: True}, + filename=f"{name}.sto", + ) + + # MAW + maw = flopy.mf6.ModflowGwfmaw( + gwf, + filename=f"{name}.maw", + print_input=True, + print_head=True, + print_flows=True, + save_flows=True, + observations=data.well.observations, + packagedata=data.well.packagedata, + connectiondata=data.well.connectiondata, + perioddata=data.well.perioddata, + ) + + # output control + oc = flopy.mf6.ModflowGwfoc( + gwf, + budget_filerecord=f"{name}.cbc", + head_filerecord=f"{name}.hds", + headprintrecord=[ + ("COLUMNS", data.ncol, "WIDTH", 15, "DIGITS", 6, "GENERAL") + ], + saverecord=[("HEAD", "ALL")], + printrecord=[("HEAD", "ALL"), ("BUDGET", "ALL")], + filename=f"{name}.oc", + ) + + # head observations + obs_data0 = [("head_well_cell", "HEAD", (0, 0, 0))] + obs_recarray = {f"{name}.obs.csv": obs_data0} + obs = flopy.mf6.ModflowUtlobs( + gwf, + pname="head_obs", + filename=f"{name}.obs", + digits=15, + print_input=True, + continuous=obs_recarray, + ) + + return data, sim, None, self.eval_3 + + def eval_3(self, config, data): + print("evaluating MAW heads...") + + # MODFLOW 6 maw results + test_name = config.name + case_name = data.name + fpth = os.path.join(config.simpath, f"{test_name}.maw.obs.csv") + tc = np.genfromtxt(fpth, names=True, delimiter=",") + + if case_name == "a": + + # M1RATE should be 2000. + msg = "The injection rate should be 2000. for all times" + assert tc["M1RATE"].min() == tc["M1RATE"].max() == 2000, msg + + elif case_name == "b": + + # M1RATE should have a minimum value less than 200 and + # M1HEAD should not exceed 0.400001 + msg = ( + "Injection rate should fall below 200 and the head should not" + "exceed 0.4" + ) + assert tc["M1RATE"].min() < 200.0, msg + assert tc["M1HEAD"].max() < 0.400001, msg + + elif case_name == "c": + + # M1RATE should have a minimum value less than 800 + # M1HEAD should not exceed 1.0. + msg = ( + "Min injection rate should be less than 800 and well " + "head should not exceed 1.0" + ) + assert tc["M1RATE"].min() < 800.0 and tc["M1HEAD"].max() < 1.0, msg + + # TODO + # case4 = Case( + # name='maw_iss305', + # krylov='CG', + # nlay=2, + # nrow=101, + # ncol=101, + # nper=2, + # delr=142, + # delc=142, + # perlen=[0.0, 365.0], + # nstp=[1, 25], + # tsmult=[1.0, 1.1], + # steady=[True, False], + # well=None, + # strt=0, + # hk=10, + # nouter=100, + # ninner=100, + # hclose=1e-9, + # rclose=1e-6, + # relax=1, + # require_failure=True + # ) + # cases4 = [ + # case4.copy_update({ + # 'name': "maw_iss305a", + # 'well': well4(case4, "CUMULATIVE"), + # 'require_failure': False + # }), + # case4.copy_update({ + # 'name': "maw_iss305b", + # 'well': well4(case4, "SKIN") + # }), + # case4.copy_update({ + # 'name': "maw_iss305c", + # 'well': well4(case4, "SKIN") + # }), + # case4.copy_update({ + # 'name': "maw_iss305d", + # 'well': well4(case4, "SKIN") + # }), + # case4.copy_update({ + # 'name': "maw_iss305e", + # 'well': well4(case4, "SPECIFIED") + # }), + # case4.copy_update({ + # 'name': "maw_iss305f", + # 'well': well4(case4, "CUMULATIVE") + # }) + # ] + + # @parametrize(data=cases4, ids=[c['name'] for c in cases4]) + # def case_4(self, function_tmpdir, targets, data): + # pass + + # def eval_4(self, sim, data): + # pass diff --git a/autotest/test_gwf_maw_obs.py b/autotest/test_gwf_maw_obs.py index 21ee3503b39..7455949fc37 100644 --- a/autotest/test_gwf_maw_obs.py +++ b/autotest/test_gwf_maw_obs.py @@ -6,39 +6,14 @@ import os -import shutil -import numpy as np -import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -import targets - -mf6_exe = os.path.abspath(targets.target_dict["mf6"]) +import flopy newtonoptions = [None, "NEWTON", "NEWTON UNDER_RELAXATION"] ex = "maw_obs" -exdir = os.path.join("temp", ex) -ddir = "data" - -def build_model(): +def build_model(dir, exe): nlay, nrow, ncol = 1, 1, 3 nper = 3 @@ -63,9 +38,9 @@ def build_model(): name = ex # build MODFLOW 6 files - ws = exdir + ws = dir sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name=mf6_exe, sim_ws=ws + sim_name=name, version="mf6", exe_name=exe, sim_ws=ws ) # create tdis package tdis = flopy.mf6.ModflowTdis( @@ -192,18 +167,14 @@ def build_model(): return sim -def test_mf6model(): - # build the models - sim = build_model() - - # write model input +def test_mf6model(function_tmpdir, targets): + mf6 = targets["mf6"] + sim = build_model(str(function_tmpdir), mf6) sim.write_simulation() - - # attempt to run model should fail sim.run_simulation() # ensure that the error msg is contained in the mfsim.lst file - f = open(os.path.join(exdir, "mfsim.lst"), "r") + f = open(str(function_tmpdir / "mfsim.lst"), "r") lines = f.readlines() error_count = 0 expected_msg = False @@ -217,8 +188,8 @@ def test_mf6model(): ) # fix the error and attempt to rerun model - orig_fl = os.path.join(exdir, ex + ".maw.obs") - new_fl = os.path.join(exdir, ex + ".maw.obs.new") + orig_fl = str(function_tmpdir / (ex + ".maw.obs")) + new_fl = str(function_tmpdir / (ex + ".maw.obs.new")) sr = open(orig_fl, "r") sw = open(new_fl, "w") @@ -241,19 +212,3 @@ def test_mf6model(): success, buff = sim.run_simulation() assert success, "model rerun failed" - - shutil.rmtree(exdir, ignore_errors=True) - - -def main(): - test_mf6model() - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_multimvr.py b/autotest/test_gwf_multimvr.py index 59bcef3a48e..9fddf576be0 100644 --- a/autotest/test_gwf_multimvr.py +++ b/autotest/test_gwf_multimvr.py @@ -1,30 +1,14 @@ import math import os -import shutil +import flopy import numpy as np import pytest +from flopy.utils.lgrutil import Lgr +from framework import TestFramework +from simulation import TestSimulation -import targets - -try: - import flopy - from flopy.utils.lgrutil import Lgr -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -mf6exe = os.path.abspath(targets.target_dict["mf6"]) - -name = "gwf" mvr_scens = ["mltmvr", "mltmvr5050", "mltmvr7525"] -ws = os.path.join("temp", name) -exdirs = [f"{ws}-{s}" for s in mvr_scens] sim_workspaces = [] gwf_names = [] @@ -583,9 +567,9 @@ def instantiate_base_simulation(sim_ws, gwfname, gwfnamec): sim_workspaces.append(sim_ws) gwf_names.append(gwfname) sim = flopy.mf6.MFSimulation( - sim_name=name, + sim_name="gwf", version="mf6", - exe_name=mf6exe, + exe_name="mf6", sim_ws=sim_ws, continue_=False, ) @@ -837,7 +821,7 @@ def instantiate_base_simulation(sim_ws, gwfname, gwfnamec): nexg=len(exchange_data), exchangedata=exchange_data, pname="EXG-1", - filename=f"{name}.exg", + filename=f"gwf.exg", ) return sim, gwf, gwfc @@ -982,7 +966,7 @@ def add_sim_mvr(sim, gwfname, gwfnamec, remaining_frac=None): maxpackages=maxpackages, packages=mvrpack_sim, perioddata=mvrspd, - filename=f"{name}.mvr", + filename=f"gwf.mvr", ) @@ -993,8 +977,8 @@ def build_model(idx, sim_ws): scen_conns[idx], parent_mvr_frac[idx], ) - scen_nm_parent = name + "_" + scen_nm + "_p" - scen_nm_child = name + "_" + scen_nm + "_c" + scen_nm_parent = "gwf_" + scen_nm + "_p" + scen_nm_child = "gwf_" + scen_nm + "_c" sim, gwf, gwfc = instantiate_base_simulation( sim_ws, scen_nm_parent, scen_nm_child ) @@ -1021,9 +1005,9 @@ def check_simulation_output(sim): gwf_srch_str2 = " WATER MOVER PACKAGE (MVR) FLOW RATES " sim_srch_str = " WATER MOVER PACKAGE (MVR) FLOW RATES " - # cur_ws, gwfparent = exdirs[idx], gwf_names[idx] - cur_ws = exdirs[idx] - gwfparent = name + "_" + mvr_scens[idx] + "_p" + # cur_ws, gwfparent = ex[idx], gwf_names[idx] + cur_ws = sim.simpath + gwfparent = "gwf_" + mvr_scens[idx] + "_p" with open(os.path.join(cur_ws, gwfparent + ".lst"), "r") as gwf_lst, open( os.path.join(cur_ws, "mfsim.lst"), "r" ) as sim_lst: @@ -1130,48 +1114,19 @@ def check_simulation_output(sim): ) -# - No need to change any code below - - @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(mvr_scens)), ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, exdir) - - test.run_mf6( - Simulation( - exdir, +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=check_simulation_output, idxsim=idx, - ) + ), + str(function_tmpdir), ) - - -def main(): - # initialize testing framework - test = testing_framework() - - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - sim = Simulation( - exdir, - exfunc=check_simulation_output, - idxsim=idx, - ) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_mvr01.py b/autotest/test_gwf_mvr01.py index d971945a7c7..8ba4f45b1e1 100644 --- a/autotest/test_gwf_mvr01.py +++ b/autotest/test_gwf_mvr01.py @@ -1,22 +1,13 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation name = "gwf_mvr01" -ws = os.path.join("temp", name) -exdirs = [ws] +ex = [name] def build_model(idx, dir): @@ -45,7 +36,7 @@ def build_model(idx, dir): # build MODFLOW 6 files sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws + sim_name=name, version="mf6", exe_name="mf6", sim_ws=str(dir) ) # create tdis package tdis = flopy.mf6.ModflowTdis( @@ -453,39 +444,19 @@ def eval_model(sim): ) assert records[24].shape == (0,) - return -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_newton01.py b/autotest/test_gwf_newton01.py index ca733eba833..60c83c8f768 100644 --- a/autotest/test_gwf_newton01.py +++ b/autotest/test_gwf_newton01.py @@ -1,26 +1,12 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["newton01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - nlay = 2 nrow, ncol = 3, 3 top = 20 @@ -31,10 +17,7 @@ chdloc = [(1, i, j) for i in range(nrow) for j in range(ncol)] chd = 7.0 strt = chd - -# recharge data rch = 1.0 - oname = "head_obs.csv" obs_recarray = {oname: [("h1", "HEAD", (0, 1, 1)), ("h2", "HEAD", (1, 1, 1))]} @@ -125,40 +108,13 @@ def eval_head(sim): msg = f"head in layer 2 != 7. ({v['H2']})" assert np.allclose(v["H2"], 7.0), msg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_head)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_head) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run(TestSimulation(name=name, exe_dict=targets, exfunc=eval_head), ws) diff --git a/autotest/test_gwf_noptc01.py b/autotest/test_gwf_noptc01.py index 2addf94f33e..d32c04fdecb 100644 --- a/autotest/test_gwf_noptc01.py +++ b/autotest/test_gwf_noptc01.py @@ -1,36 +1,13 @@ import os -import numpy as np +import flopy import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwf_noptc01", "gwf_noptc02", "gwf_noptc03"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - no_ptcrecords = ["FIRST", "ALL", None] - -ddir = "data" - -## run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -# replace_exe = {'mf2005': 'mf2005devdbl'} -replace_exe = None - -htol = [None for idx in range(len(exdirs))] +htol = [None for idx in range(len(ex))] # static model data # temporal discretization @@ -156,49 +133,12 @@ def build_model(idx, dir): return sim, mc -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6(Simulation(dir, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, idxsim=idx) - test.run_mf6(sim) - - return - - -# use python testmf6_csub_sub03.py --mf2005 mf2005devdbl -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run(TestSimulation(name=name, exe_dict=targets, idxsim=idx), ws) diff --git a/autotest/test_gwf_npf01_75x75.py b/autotest/test_gwf_npf01_75x75.py index 74ca2cb494d..e976784b582 100644 --- a/autotest/test_gwf_npf01_75x75.py +++ b/autotest/test_gwf_npf01_75x75.py @@ -1,29 +1,16 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["npf01a_75x75", "npf01b_75x75"] top = [100.0, 0.0] laytyp = [1, 0] ss = [0.0, 1.0e-4] sy = [0.1, 0.0] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -205,35 +192,10 @@ def build_model(idx, dir): # - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models_legacy(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models_legacy(build_model, idx, dir) - sim = Simulation(dir) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + test = TestFramework() + test.build(build_model, idx, str(function_tmpdir)) + test.run(TestSimulation(name=name, exe_dict=targets), str(function_tmpdir)) diff --git a/autotest/test_gwf_npf02_rewet.py b/autotest/test_gwf_npf02_rewet.py index 353b85bd9cb..96eb0e8d4ab 100644 --- a/autotest/test_gwf_npf02_rewet.py +++ b/autotest/test_gwf_npf02_rewet.py @@ -1,25 +1,12 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["npf02_hreweta", "npf02_hrewetb", "npf02_hrewetc", "npf02_hrewetd"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" ncols = [[15], [10, 5], [15], [10, 5]] nlays = [1, 1, 3, 3] @@ -349,42 +336,18 @@ def eval_hds(sim): sim.success = True print(" " + msg) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_hds, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_hds, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_hds, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_npf03_sfr.py b/autotest/test_gwf_npf03_sfr.py index ce3cc623fb1..d4490ea4146 100644 --- a/autotest/test_gwf_npf03_sfr.py +++ b/autotest/test_gwf_npf03_sfr.py @@ -1,37 +1,18 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from conftest import project_root_path +from framework import TestFramework +from simulation import TestSimulation ex = ["npf03_sfra", "npf03_sfrb"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - -# run all examples on CI -continuous_integration = [True for idx in range(len(exdirs))] -# continuous_integration = [False for idx in range(len(exdirs))] - -# read hk data -fpth = os.path.join(ddir, "npf03_hk.ref") +fpth = str(project_root_path / "autotest" / "data" / "npf03_hk.ref") shape = (50, 108) hk = flopy.utils.Util2d.load_txt(shape, fpth, dtype=float, fmtin="(FREE)") n1 = hk.shape[1] nd = 40 - ncols = [[n1], [n1 - nd, nd]] # static model data @@ -5794,47 +5775,19 @@ def eval_hds(sim): sim.success = True print(" " + msg) - return - -# - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # determine if running on CI infrastructure - is_CI = running_on_CI() - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6(Simulation(dir, exfunc=eval_hds, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_hds, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_hds, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_npf04_spdis.py b/autotest/test_gwf_npf04_spdis.py index 34e4e2a9ceb..b771b1b4161 100644 --- a/autotest/test_gwf_npf04_spdis.py +++ b/autotest/test_gwf_npf04_spdis.py @@ -9,28 +9,15 @@ """ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy - from flopy.utils.lgrutil import Lgr -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from flopy.utils.lgrutil import Lgr +from framework import TestFramework +from simulation import TestSimulation ex = ["npf04"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - namea = "a" nameb = "b" @@ -224,42 +211,18 @@ def eval_mf6(sim): errmsg = f"min or max residual too large {res.min()} {res.max()}" assert np.allclose(res, 0.0, atol=1.0e-6), errmsg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_mf6, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_mf6, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_mf6, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_npf05_anisotropy.py b/autotest/test_gwf_npf05_anisotropy.py index e9e9e0d4048..cb6e46e0272 100644 --- a/autotest/test_gwf_npf05_anisotropy.py +++ b/autotest/test_gwf_npf05_anisotropy.py @@ -5,34 +5,14 @@ """ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["npf05a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -165,39 +145,19 @@ def eval_model(sim): ] answer = np.array(answer) assert np.allclose(heads.flatten(), answer) - return -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_npf_tvk01.py b/autotest/test_gwf_npf_tvk01.py index 53ca8c37a43..f7791a3c6cc 100644 --- a/autotest/test_gwf_npf_tvk01.py +++ b/autotest/test_gwf_npf_tvk01.py @@ -1,36 +1,12 @@ import os -import sys +import flopy import numpy as np import pytest +from framework import TestFramework +from simulation import TestSimulation -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -ex = [ - "tvk01", -] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - +ex = ["tvk01"] time_varying_k = [1.0, 10.0] @@ -165,8 +141,7 @@ def build_model(idx, dir): def eval_model(sim): print("evaluating model...") - name = ex[sim.idxsim] - gwfname = "gwf_" + name + gwfname = "gwf_" + sim.name # head fpth = os.path.join(sim.simpath, f"{gwfname}.hds") @@ -185,7 +160,7 @@ def eval_model(sim): assert False, f'could not load data from "{fpth}"' # This is the answer to this problem. - hk = time_varying_k[sim.idxsim] + hk = time_varying_k[0] delc = 1.0 delr = 1.0 delz = 1.0 @@ -203,39 +178,18 @@ def eval_model(sim): # comment when done testing # assert False - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwf_npf_tvk02.py b/autotest/test_gwf_npf_tvk02.py index 2cb79d6acca..48d30e65a0d 100644 --- a/autotest/test_gwf_npf_tvk02.py +++ b/autotest/test_gwf_npf_tvk02.py @@ -1,35 +1,12 @@ import os -import sys +import flopy import numpy as np import pytest +from framework import TestFramework +from simulation import TestSimulation -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -ex = [ - "tvk02", -] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" +ex = ["tvk02"] def build_model(idx, dir): @@ -184,8 +161,7 @@ def build_model(idx, dir): def eval_model(sim): print("evaluating model...") - name = ex[sim.idxsim] - gwfname = "gwf_" + name + gwfname = "gwf_" + sim.name # head fpth = os.path.join(sim.simpath, f"{gwfname}.hds") @@ -228,39 +204,18 @@ def eval_model(sim): # comment when done testing # assert False - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwf_npf_tvk03.py b/autotest/test_gwf_npf_tvk03.py index 20d47db9c75..226ee8bc932 100644 --- a/autotest/test_gwf_npf_tvk03.py +++ b/autotest/test_gwf_npf_tvk03.py @@ -1,35 +1,12 @@ import os -import sys +import flopy import numpy as np import pytest +from framework import TestFramework +from simulation import TestSimulation -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -ex = [ - "tvk03", -] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" +ex = ["tvk03"] def build_model(idx, dir): @@ -184,8 +161,7 @@ def build_model(idx, dir): def eval_model(sim): print("evaluating model...") - name = ex[sim.idxsim] - gwfname = "gwf_" + name + gwfname = "gwf_" + sim.name # head fpth = os.path.join(sim.simpath, f"{gwfname}.hds") @@ -228,39 +204,18 @@ def eval_model(sim): # comment when done testing # assert False - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwf_npf_tvk04.py b/autotest/test_gwf_npf_tvk04.py index eef8bff16f0..67b3c980c33 100644 --- a/autotest/test_gwf_npf_tvk04.py +++ b/autotest/test_gwf_npf_tvk04.py @@ -1,36 +1,12 @@ import os -import sys +import flopy import numpy as np import pytest +from framework import TestFramework +from simulation import TestSimulation -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -ex = [ - "tvk05", -] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - +ex = ["tvk05"] time_varying_k = [1.0, 10.0] @@ -182,11 +158,9 @@ def build_model(idx, dir): def eval_model(sim): print("evaluating model...") - name = ex[sim.idxsim] - # budget try: - fname = f"gwf_{name}.lst" + fname = f"gwf_{sim.name}.lst" ws = sim.simpath fname = os.path.join(ws, fname) lst = flopy.utils.Mf6ListBudget( @@ -209,39 +183,18 @@ def eval_model(sim): errmsg = f"Expect higher flow rate in period 2 compared to period 1, but found equal or higher flow rate in period 1" assert 2.0 * sp_x[0][8] < sp_x[1][8], errmsg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() \ No newline at end of file +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwf_npf_tvk05.py b/autotest/test_gwf_npf_tvk05.py index 44b265f99d9..99059f5d9f0 100644 --- a/autotest/test_gwf_npf_tvk05.py +++ b/autotest/test_gwf_npf_tvk05.py @@ -1,36 +1,12 @@ import os -import sys +import flopy import numpy as np import pytest +from framework import TestFramework +from simulation import TestSimulation -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -ex = [ - "tvk05", -] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - +ex = ["tvk05"] time_varying_k = [1.0, 10.0] @@ -183,11 +159,9 @@ def build_model(idx, dir): def eval_model(sim): print("evaluating model...") - name = ex[sim.idxsim] - # budget try: - fname = f"gwf_{name}.lst" + fname = f"gwf_{sim.name}.lst" ws = sim.simpath fname = os.path.join(ws, fname) lst = flopy.utils.Mf6ListBudget( @@ -210,39 +184,18 @@ def eval_model(sim): errmsg = f"Period 2 budget should be exactly the same as period 1" assert sp_x[0][8] == sp_x[1][8], errmsg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() \ No newline at end of file +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwf_obs01.py b/autotest/test_gwf_obs01.py index 39256e24893..bcee2743b56 100644 --- a/autotest/test_gwf_obs01.py +++ b/autotest/test_gwf_obs01.py @@ -1,34 +1,13 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation cell_dimensions = (300,) ex = [f"gwf_obs01{chr(ord('a') + idx)}" for idx in range(len(cell_dimensions))] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - h0, h1 = 1.0, 0.0 @@ -164,42 +143,19 @@ def eval_model(sim): msg = "simulated head observations do not match with known solution." assert np.allclose(hres, obs), msg - return - -# - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build all of the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build all of the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_obs02.py b/autotest/test_gwf_obs02.py index 5e2cb0aff7b..bfef5b1a50e 100644 --- a/autotest/test_gwf_obs02.py +++ b/autotest/test_gwf_obs02.py @@ -4,35 +4,14 @@ """ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation cell_dimensions = (300,) ex = ["gwf_obs02"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - h0, h1 = 1.0, 0.0 nlay, nrow, ncol = 1, 10, 10 @@ -147,10 +126,9 @@ def build_model(idx, dir): def eval_model(sim): print("evaluating model observations...") - name = ex[sim.idxsim] headcsv = np.empty((nlay, nrow, ncol), dtype=float) for i in range(nrow): - fname = f"{name}.{i}.obs.csv" + fname = f"{sim.name}.{i}.obs.csv" print(f"Loading and testing {fname}") fname = os.path.join(sim.simpath, fname) rec = np.genfromtxt(fname, names=True, delimiter=",", deletechars="") @@ -164,7 +142,7 @@ def eval_model(sim): assert obsname_true == obsname_found, errmsg headcsv[0, i, :] = np.array(rec.tolist()[1:]) - fn = os.path.join(sim.simpath, f"{name}.hds") + fn = os.path.join(sim.simpath, f"{sim.name}.hds") hobj = flopy.utils.HeadFile(fn) headbin = hobj.get_data() @@ -172,42 +150,18 @@ def eval_model(sim): headcsv, headbin ), "headcsv not equal head from binary file" - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build all of the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build all of the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwf_ptc01.py b/autotest/test_gwf_ptc01.py index af8197c9f7f..992deb59313 100644 --- a/autotest/test_gwf_ptc01.py +++ b/autotest/test_gwf_ptc01.py @@ -1,28 +1,15 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from conftest import project_root_path +from framework import TestFramework +from simulation import TestSimulation ex = ["ptc01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - -# read bottom data -fpth = os.path.join(ddir, "nwtp03_bot.ref") +data_path = project_root_path / "autotest" / "data" +fpth = str(data_path / "nwtp03_bot.ref") botm = np.loadtxt(fpth, dtype=float) nlay = 1 nrow, ncol = botm.shape @@ -37,7 +24,7 @@ strt = botm + 20.0 # read recharge data -fpth = os.path.join(ddir, "nwtp03_rch.ref") +fpth = str(data_path / "nwtp03_rch.ref") rch = np.loadtxt(fpth, dtype=float) @@ -156,39 +143,13 @@ def build_model(idx, dir): return sim, mc -# - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for dir in exdirs: - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run(TestSimulation(name=name, exe_dict=targets), ws) diff --git a/autotest/test_gwf_rch01.py b/autotest/test_gwf_rch01.py index f36d6465411..879739313f5 100644 --- a/autotest/test_gwf_rch01.py +++ b/autotest/test_gwf_rch01.py @@ -9,35 +9,15 @@ """ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["rch01a", "rch01b", "rch01c"] irch = [None, 0, [1, 1, 0, 1, 1]] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -160,39 +140,18 @@ def eval_model(sim): hobj = flopy.utils.HeadFile(fpth, precision="double") heads = hobj.get_alldata() - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_rch02.py b/autotest/test_gwf_rch02.py index 69f0d2645cd..e7aced8d6ff 100644 --- a/autotest/test_gwf_rch02.py +++ b/autotest/test_gwf_rch02.py @@ -5,34 +5,14 @@ """ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["rch02"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -152,39 +132,18 @@ def eval_model(sim): hobj = flopy.utils.HeadFile(fpth, precision="double") heads = hobj.get_alldata() - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_rch03.py b/autotest/test_gwf_rch03.py index b4ffea4e22d..c853cd4eaef 100644 --- a/autotest/test_gwf_rch03.py +++ b/autotest/test_gwf_rch03.py @@ -5,34 +5,14 @@ """ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["rch03"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -178,39 +158,18 @@ def eval_model(sim): hobj = flopy.utils.HeadFile(fpth, precision="double") heads = hobj.get_alldata() - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_returncodes.py b/autotest/test_gwf_returncodes.py index 9201054d3df..3eda6b7ef76 100644 --- a/autotest/test_gwf_returncodes.py +++ b/autotest/test_gwf_returncodes.py @@ -1,25 +1,11 @@ import os -import shutil import subprocess import sys +import flopy import pytest -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -import targets - -mf6_exe = os.path.abspath(targets.target_dict["mf6"]) name = "gwf_ret_codes01" -base_ws = os.path.join("temp", name) -if not os.path.isdir(base_ws): - os.makedirs(base_ws, exist_ok=True) app = "mf6" if sys.platform.lower() == "win32": app += ".exe" @@ -40,7 +26,7 @@ def run_mf6(argv, ws): return proc.returncode, buff -def get_sim(ws, idomain, continue_flag=False, nouter=500): +def get_sim(ws, exe, idomain, continue_flag=False, nouter=500): # static model data # temporal discretization nper = 1 @@ -66,7 +52,7 @@ def get_sim(ws, idomain, continue_flag=False, nouter=500): sim = flopy.mf6.MFSimulation( sim_name=name, version="mf6", - exe_name=mf6_exe, + exe_name=exe, sim_ws=ws, continue_=continue_flag, ) @@ -143,17 +129,17 @@ def get_sim(ws, idomain, continue_flag=False, nouter=500): return sim -def normal_termination(): - ws = os.path.join(base_ws, "normal_termination") +def normal_termination(dir, exe): + ws = os.path.join(dir, "normal_termination") # get the simulation - sim = get_sim(ws, idomain=1) + sim = get_sim(ws, exe, idomain=1) # write the input files sim.write_simulation() # run the simulation - returncode, buff = run_mf6([mf6_exe], ws) + returncode, buff = run_mf6([exe], ws) if returncode != 0: msg = ( "The run should have been successful but it terminated " @@ -161,79 +147,69 @@ def normal_termination(): ) raise ValueError(msg) - # clean up working directory - clean(ws) - - return - -def converge_fail_continue(): - ws = os.path.join(base_ws, "converge_fail_continue") +def converge_fail_continue(dir, exe): + ws = os.path.join(dir, "converge_fail_continue") # get the simulation - sim = get_sim(ws, idomain=1, continue_flag=True, nouter=1) + sim = get_sim(ws, exe, idomain=1, continue_flag=True, nouter=1) # write the input files sim.write_simulation() # run the simulation - returncode, buff = run_mf6([mf6_exe], ws) + returncode, buff = run_mf6([exe], ws) msg = ( "The run should have been successful even though it failed, because" " the continue flag was set. But a non-zero error code was " "found: {}".format(returncode) ) assert returncode == 0, msg - return -def converge_fail_nocontinue(): - ws = os.path.join(base_ws, "converge_fail_nocontinue") +def converge_fail_nocontinue(dir, exe): + ws = os.path.join(dir, "converge_fail_nocontinue") with pytest.raises(RuntimeError): # get the simulation - sim = get_sim(ws, idomain=1, continue_flag=False, nouter=1) + sim = get_sim(ws, exe, idomain=1, continue_flag=False, nouter=1) # write the input files sim.write_simulation() # run the simulation - returncode, buff = run_mf6([mf6_exe], ws) + returncode, buff = run_mf6([exe], ws) msg = "This run should fail with a returncode of 1" if returncode == 1: - clean(ws) raise RuntimeError(msg) -def idomain_runtime_error(): - ws = os.path.join(base_ws, "idomain_runtime_error") +def idomain_runtime_error(dir, exe): + ws = os.path.join(dir, "idomain_runtime_error") with pytest.raises(RuntimeError): # get the simulation - sim = get_sim(ws, idomain=0) + sim = get_sim(ws, exe, idomain=0) # write the input files sim.write_simulation() # run the simulation - returncode, buff = run_mf6([mf6_exe], ws) + returncode, buff = run_mf6([exe], ws) msg = f"could not run {sim.name}" if returncode != 0: err_str = "Ensure IDOMAIN array has some" err = any(err_str in s for s in buff) if err: - clean(ws) raise RuntimeError(msg) else: msg += " but IDOMAIN ARRAY ERROR not returned" raise ValueError(msg) -def unknown_keyword_error(): - ws = base_ws - - with pytest.raises(RuntimeError): - returncode, buff = run_mf6([mf6_exe, "--unknown_keyword"], ws) +def unknown_keyword_error(dir, exe): + with pytest.raises((RuntimeError, ValueError)): + returncode, buff = run_mf6([exe, "--unknown_keyword"], dir) msg = "could not run unknown_keyword" if returncode != 0: err_str = f"{app}: illegal option" @@ -245,10 +221,8 @@ def unknown_keyword_error(): raise ValueError(msg) -def run_argv(arg, return_str): - ws = base_ws - - returncode, buff = run_mf6([mf6_exe, arg], ws) +def run_argv(arg, return_str, tempdir, exe): + returncode, buff = run_mf6([exe, arg], tempdir) if returncode == 0: found_str = any(return_str in s for s in buff) if not found_str: @@ -259,62 +233,43 @@ def run_argv(arg, return_str): raise RuntimeError(msg) -def help_argv(): +def help_argv(dir, exe): for arg in ["-h", "--help", "-?"]: return_str = f"{app} [options] retrieve program information" - run_argv(arg, return_str) + run_argv(arg, return_str, dir, exe) -def version_argv(): +def version_argv(dir, exe): for arg in ["-v", "--version"]: return_str = f"{app}: 6" - run_argv(arg, return_str) + run_argv(arg, return_str, dir, exe) -def develop_argv(): +def develop_argv(dir, exe): for arg in ["-dev", "--develop"]: return_str = f"{app}: develop version" - run_argv(arg, return_str) + run_argv(arg, return_str, dir, exe) -def compiler_argv(): +def compiler_argv(dir, exe): for arg in ["-c", "--compiler"]: return_str = f"{app}: MODFLOW 6 compiled" - run_argv(arg, return_str) - - -def clean(dir_pth): - print(f"Cleaning up {dir_pth}") - shutil.rmtree(dir_pth) + run_argv(arg, return_str, dir, exe) @pytest.mark.parametrize( "fn", ( - "idomain_runtime_error()", - "unknown_keyword_error()", - "normal_termination()", - "converge_fail_nocontinue()", - "help_argv()", - "version_argv()", - "develop_argv()", - "compiler_argv()", + "idomain_runtime_error", + "unknown_keyword_error", + "normal_termination", + "converge_fail_nocontinue", + "help_argv", + "version_argv", + "develop_argv", + "compiler_argv", ), ) -def test_main(fn): - eval(fn) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - idomain_runtime_error() - unknown_keyword_error() - normal_termination() - converge_fail_nocontinue() - help_argv() - version_argv() - develop_argv() - compiler_argv() - clean(base_ws) +def test_main(fn, function_tmpdir, targets): + mf6 = targets.as_dict()["mf6"] + eval(fn)(function_tmpdir, mf6) diff --git a/autotest/test_gwf_sfr_badfactor.py b/autotest/test_gwf_sfr_badfactor.py index 86c4751f93a..23677308164 100644 --- a/autotest/test_gwf_sfr_badfactor.py +++ b/autotest/test_gwf_sfr_badfactor.py @@ -1,33 +1,11 @@ -import os -import shutil -import subprocess -import sys - +import flopy import numpy as np -import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -import targets -from framework import testing_framework -from simulation import Simulation - -mf6_exe = os.path.abspath(targets.target_dict["mf6"]) paktest = "sfr" testname = "ts_sfr01" -testdir = os.path.join("temp", testname) -os.makedirs(testdir, exist_ok=True) -everything_was_successful = True -def build_model(timeseries=False): +def build_model(ws, exe, timeseries=False): # static model data # temporal discretization nper = 1 @@ -57,9 +35,8 @@ def build_model(timeseries=False): # build MODFLOW 6 files name = testname - ws = testdir sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name=mf6_exe, sim_ws=ws + sim_name=name, version="mf6", exe_name=exe, sim_ws=ws ) # create tdis package tdis = flopy.mf6.ModflowTdis( @@ -529,40 +506,16 @@ def build_model(timeseries=False): return sim -# - No need to change any code below -def test_mf6model(): - # build and run the test model - sim = build_model() - sim.write_simulation() - sim.run_simulation() - - # ensure that the error msg is contained in the mfsim.lst file - f = open(os.path.join(testdir, "mfsim.lst"), "r") - lines = f.readlines() - error_count = 0 - expected_msg = False - for line in lines: - if "cprior" and "divflow not within" in line: - expected_msg = True - error_count += 1 - - assert error_count == 1, ( - "error count = " + str(error_count) + "but should equal 1" - ) - - print("Finished running surfdep check") - - return - +def test_mf6model(function_tmpdir, targets): + mf6 = targets.mf6 -def main(): # build and run the test model - sim = build_model() + sim = build_model(str(function_tmpdir), mf6) sim.write_simulation() sim.run_simulation() # ensure that the error msg is contained in the mfsim.lst file - f = open(os.path.join(testdir, "mfsim.lst"), "r") + f = open(str(function_tmpdir / "mfsim.lst"), "r") lines = f.readlines() error_count = 0 expected_msg = False @@ -576,13 +529,3 @@ def main(): ) print("Finished running surfdep check") - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_sfr_evap.py b/autotest/test_gwf_sfr_evap.py index 8f57ab4c9bd..8684476c33b 100644 --- a/autotest/test_gwf_sfr_evap.py +++ b/autotest/test_gwf_sfr_evap.py @@ -1,28 +1,14 @@ # Test evap in SFR reaches (no interaction with gwf) -# Imports - import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["sfr-evap"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # Model units @@ -448,36 +434,17 @@ def eval_results(sim): assert np.allclose(stored_strm_evap_r, sim_evap_r, atol=1e-4), msg -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_sfr_npoint01.py b/autotest/test_gwf_sfr_npoint01.py index a63b85f88fb..4106805eac5 100644 --- a/autotest/test_gwf_sfr_npoint01.py +++ b/autotest/test_gwf_sfr_npoint01.py @@ -1,25 +1,13 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -sys.path.append("scripts") from cross_section_functions import get_depths +from framework import TestFramework +from simulation import TestSimulation paktest = "sfr" - ex = [ "sfr_npt01a", "sfr_npt01b", @@ -31,7 +19,6 @@ "sfr_npt01h", "sfr_npt01i", ] -exdirs = [os.path.join("temp", s) for s in ex] xsect_types = ( "wide", @@ -298,12 +285,10 @@ def build_model(idx, ws): return sim, None -def eval_npointq(sim): - idx = sim.idxsim - name = ex[idx] - print("evaluating n-point cross-section results..." f"({name})") +def eval_npointq(sim, idx): + print("evaluating n-point cross-section results..." f"({sim.name})") - obs_pth = os.path.join(exdirs[idx], f"{name}.sfr.obs.csv") + obs_pth = os.path.join(sim.simpath, f"{sim.name}.sfr.obs.csv") obs = flopy.utils.Mf6Obs(obs_pth).get_data() assert np.allclose( @@ -327,51 +312,21 @@ def eval_npointq(sim): f"calculated depth: {d}" ) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # run the test models - test.run_mf6( - Simulation( - exdir, - exfunc=eval_npointq, +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, + exe_dict=targets, + exfunc=lambda s: eval_npointq(s, idx), idxsim=idx, - ) + ), + ws, ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - - sim = Simulation( - exdir, - exfunc=eval_npointq, - idxsim=idx, - ) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_sfr_npoint02.py b/autotest/test_gwf_sfr_npoint02.py index d54d404009f..dd49ecc1a29 100644 --- a/autotest/test_gwf_sfr_npoint02.py +++ b/autotest/test_gwf_sfr_npoint02.py @@ -1,25 +1,16 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation paktest = "sfr" ex = [ "sfr_npt02a", ] -exdirs = [os.path.join("temp", s) for s in ex] # temporal discretization nper = 10 @@ -218,11 +209,10 @@ def build_model(idx, ws): def eval_npointdepth(sim): - idx = sim.idxsim - name = ex[idx] + name = sim.name print("evaluating n-point cross-section results..." f"({name})") - obs_pth = os.path.join(exdirs[idx], f"{name}.sfr.obs.csv") + obs_pth = os.path.join(sim.simpath, f"{name}.sfr.obs.csv") obs = flopy.utils.Mf6Obs(obs_pth).get_data() assert np.allclose( @@ -238,51 +228,21 @@ def eval_npointdepth(sim): obs["DEPTH"], d ), "sfr depth not equal to calculated depth" - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # run the test models - test.run_mf6( - Simulation( - exdir, +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_npointdepth, - idxsim=idx, - ) + idxsim=0, + ), + ws, ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - - sim = Simulation( - exdir, - exfunc=eval_npointdepth, - idxsim=idx, - ) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_sfr_npoint03.py b/autotest/test_gwf_sfr_npoint03.py index b69e4d88a81..cecbdc67cbf 100644 --- a/autotest/test_gwf_sfr_npoint03.py +++ b/autotest/test_gwf_sfr_npoint03.py @@ -1,25 +1,13 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -sys.path.append("scripts") from cross_section_functions import calculate_rectchan_mannings_discharge +from framework import TestFramework +from simulation import TestSimulation paktest = "sfr" - ex = [ "sfr_npt03a", "sfr_npt03b", @@ -29,7 +17,6 @@ "sfr_npt03f", "sfr_npt03g", ] -exdirs = [os.path.join("temp", s) for s in ex] simulated_depths = ( 0.5, @@ -281,69 +268,37 @@ def build_models(idx, ws): def eval_npointdepth(sim): - idx = sim.idxsim - name = ex[idx] - print("evaluating n-point cross-section results..." f"({name})") + print("evaluating n-point cross-section results..." f"({sim.name})") - obs_pth0 = os.path.join(exdirs[idx], f"{name}.sfr.obs.csv") + obs_pth0 = os.path.join(sim.simpath, f"{sim.name}.sfr.obs.csv") obs0 = np.genfromtxt(obs_pth0, names=True, delimiter=",") - obs_pth1 = os.path.join(exdirs[idx], "mf6", f"{name}.sfr.obs.csv") + obs_pth1 = os.path.join(sim.simpath, "mf6", f"{sim.name}.sfr.obs.csv") obs1 = np.genfromtxt(obs_pth1, names=True, delimiter=",") q0 = obs0["OUTFLOW_DOWNSTREAM"] q1 = obs1["OUTFLOW_DOWNSTREAM"] - assert np.allclose(q0, q1), f"downstream outflows not equal ('{name}')" + assert np.allclose(q0, q1), f"downstream outflows not equal ('{sim.name}')" d0 = obs0["DEPTH_UPSTREAM"] d1 = obs1["DEPTH_UPSTREAM"] - assert np.allclose(d0, d1), f"upstream depths are not equal ('{name}')" + assert np.allclose(d0, d1), f"upstream depths are not equal ('{sim.name}')" - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_models, idx, exdir) - - # run the test models - test.run_mf6( - Simulation( - exdir, +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_models, idx, ws) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_npointdepth, idxsim=idx, - ) + ), + ws, ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_models, idx, exdir) - - sim = Simulation( - exdir, - exfunc=eval_npointdepth, - idxsim=idx, - ) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_sfr_reorder.py b/autotest/test_gwf_sfr_reorder.py index 71fdfb352f6..2010b7a24cd 100644 --- a/autotest/test_gwf_sfr_reorder.py +++ b/autotest/test_gwf_sfr_reorder.py @@ -1,29 +1,13 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -sys.path.append("scripts") -from cross_section_functions import get_depths +from framework import TestFramework +from simulation import TestSimulation paktest = "sfr" - -ex = [ - "sfr_reorder", -] -exdirs = [os.path.join("temp", s) for s in ex] +ex = ["sfr_reorder"] # spatial discretization data nlay, nrow, ncol = 1, 1, 1 @@ -43,7 +27,7 @@ ustrf = 1.0 ndv = 0 -# + def build_model(idx, ws): # static model data @@ -221,14 +205,13 @@ def build_models(idx, base_ws): def eval_flows(sim): - idx = sim.idxsim - name = ex[idx] + name = sim.name print("evaluating flow results..." f"({name})") - obs_pth = os.path.join(exdirs[idx], f"{name}.sfr.obs.csv") + obs_pth = os.path.join(sim.simpath, f"{name}.sfr.obs.csv") obs0 = flopy.utils.Mf6Obs(obs_pth).get_data() - obs_pth = os.path.join(exdirs[idx], "mf6", f"{name}.sfr.obs.csv") + obs_pth = os.path.join(sim.simpath, "mf6", f"{name}.sfr.obs.csv") obs1 = flopy.utils.Mf6Obs(obs_pth).get_data() assert np.allclose(obs0["INFLOW"], obs1["INFLOW"]), "inflows are not equal" @@ -237,7 +220,7 @@ def eval_flows(sim): obs0["OUTFLOW"], obs1["OUTFLOW"] ), "outflows are not equal" - fpth = os.path.join(exdirs[idx], f"{name}.lst") + fpth = os.path.join(sim.simpath, f"{name}.lst") with open(fpth, "r") as f: lines = f.read().splitlines() @@ -257,51 +240,21 @@ def eval_flows(sim): order, actual ), "DAG did not correctly reorder reaches." - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_models, idx, exdir) - - # run the test models - test.run_mf6( - Simulation( - exdir, +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_models, idx, ws) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_flows, idxsim=idx, - ) + ), + ws, ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_models, idx, exdir) - - sim = Simulation( - exdir, - exfunc=eval_flows, - idxsim=idx, - ) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_sto01.py b/autotest/test_gwf_sto01.py index 08144c20bfe..c5328e0b3f5 100644 --- a/autotest/test_gwf_sto01.py +++ b/autotest/test_gwf_sto01.py @@ -1,39 +1,17 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwf_sto01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - cmppth = "mfnwt" tops = [0.0] - -ddir = "data" - -## run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# use default executable -replace_exe = None - -htol = [None for idx in range(len(exdirs))] +htol = [None for idx in range(len(ex))] dtol = 1e-3 budtol = 1e-2 - bud_lst = ["STO-SS_IN", "STO-SS_OUT", "STO-SY_IN", "STO-SY_OUT"] # static model data @@ -359,62 +337,22 @@ def eval_sto(sim): sim.success = True print(" " + msg) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models_legacy(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6( - Simulation( - dir, exfunc=eval_sto, exe_dict=r_exe, htol=htol[idx], idxsim=idx - ) - ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models_legacy(build_model, idx, dir) - sim = Simulation( - dir, +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_sto, - exe_dict=replace_exe, htol=htol[idx], idxsim=idx, - ) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() + ), + ws, + ) diff --git a/autotest/test_gwf_sto02.py b/autotest/test_gwf_sto02.py index f4c471afb8f..b2dd7ea9871 100644 --- a/autotest/test_gwf_sto02.py +++ b/autotest/test_gwf_sto02.py @@ -5,36 +5,14 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwf_sto02a", "gwf_sto02b"] ncols = [1, 2] - -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - nlay, nrow, = ( 1, 1, @@ -177,39 +155,21 @@ def eval_flow(sim): inc = mflist.get_incremental() print(inc) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_flow, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_flow, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, + exe_dict=targets, + exfunc=eval_flow, + idxsim=idx, + ), + ws, + ) diff --git a/autotest/test_gwf_sto03.py b/autotest/test_gwf_sto03.py index c90844c6070..b626b632d5a 100644 --- a/autotest/test_gwf_sto03.py +++ b/autotest/test_gwf_sto03.py @@ -1,43 +1,21 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = [ "gwf_sto03a", "gwf_sto03b", ] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - newton = ( False, True, ) - cmppth = "mf6" - -ddir = "data" - -## run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# use default executable -replace_exe = None - -htol = [None for idx in range(len(exdirs))] +htol = [None for idx in range(len(ex))] dtol = 1e-3 budtol = 1e-2 @@ -282,62 +260,22 @@ def eval_sto(sim): assert max_diff.sum() == 0.0, "simulated storage is not the same" - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6( - Simulation( - dir, exfunc=eval_sto, exe_dict=r_exe, htol=htol[idx], idxsim=idx - ) - ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation( - dir, +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_sto, - exe_dict=replace_exe, htol=htol[idx], idxsim=idx, - ) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() + ), + ws, + ) diff --git a/autotest/test_gwf_sto_tvs01.py b/autotest/test_gwf_sto_tvs01.py index 5f169bc6219..1f0f9da6023 100644 --- a/autotest/test_gwf_sto_tvs01.py +++ b/autotest/test_gwf_sto_tvs01.py @@ -1,35 +1,12 @@ import os -import sys +import flopy import numpy as np import pytest +from framework import TestFramework +from simulation import TestSimulation -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -ex = [ - "tvs01", -] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" +ex = ["tvs01"] def build_model(idx, dir): @@ -188,8 +165,7 @@ def build_model(idx, dir): def eval_model(sim): print("evaluating model...") - name = ex[sim.idxsim] - gwfname = "gwf_" + name + gwfname = "gwf_" + sim.name # head fpth = os.path.join(sim.simpath, f"{gwfname}.hds") @@ -228,39 +204,18 @@ def eval_model(sim): # comment when done testing # assert False - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwf_ts_lak01.py b/autotest/test_gwf_ts_lak01.py index e9fea2f9c8d..4a75c181cff 100644 --- a/autotest/test_gwf_ts_lak01.py +++ b/autotest/test_gwf_ts_lak01.py @@ -1,41 +1,15 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from flopy.utils.compare import eval_bud_diff +from framework import TestFramework +from simulation import TestSimulation paktest = "lak" budtol = 1e-2 - ex = ["ts_lak01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - -# run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None # static model data # spatial discretization @@ -355,7 +329,6 @@ def build_model(idx, dir): def eval_budget(sim): print("evaluating budgets...") - from budget_file_compare import eval_bud_diff # get ia/ja from binary grid file fname = f"{os.path.basename(sim.name)}.dis.grb" @@ -378,44 +351,19 @@ def eval_budget(sim): fpth = os.path.join(sim.simpath, fname) eval_bud_diff(fpth, cobj0, cobj1, ia, dtol=0.1) - return - - -# - No need to change any code below - +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_budget, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_budget, idxsim=idx) - test.run_mf6(sim) - return - - -# use python testmf6_drn_ddrn01.py -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_budget, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_ts_maw01.py b/autotest/test_gwf_ts_maw01.py index 0eb277a98af..53a89583870 100644 --- a/autotest/test_gwf_ts_maw01.py +++ b/autotest/test_gwf_ts_maw01.py @@ -1,30 +1,14 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from flopy.utils.compare import eval_bud_diff +from framework import TestFramework +from simulation import TestSimulation paktest = "maw" ex = [f"ts_{paktest}01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - -# run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None def get_model(ws, name, timeseries=False): @@ -431,8 +415,6 @@ def build_model(idx, dir): def eval_model(sim): print("evaluating model budgets...") - from budget_file_compare import eval_bud_diff - # get ia/ja from binary grid file fname = f"{os.path.basename(sim.name)}.dis.grb" fpth = os.path.join(sim.simpath, fname) @@ -469,43 +451,18 @@ def eval_model(sim): fpth = os.path.join(sim.simpath, fname) eval_bud_diff(fpth, cobj0, cobj1) - return - - -# - No need to change any code below - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_ts_sfr01.py b/autotest/test_gwf_ts_sfr01.py index faa6b60b334..adde4b870d4 100644 --- a/autotest/test_gwf_ts_sfr01.py +++ b/autotest/test_gwf_ts_sfr01.py @@ -1,30 +1,14 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from flopy.utils.compare import eval_bud_diff +from framework import TestFramework +from simulation import TestSimulation paktest = "sfr" ex = ["ts_sfr01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - -# run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None def get_model(ws, name, timeseries=False): @@ -546,7 +530,6 @@ def build_model(idx, dir): def eval_model(sim): print("evaluating model budgets...") - from budget_file_compare import eval_bud_diff # get ia/ja from binary grid file fname = f"{os.path.basename(sim.name)}.dis.grb" @@ -610,43 +593,18 @@ def eval_model(sim): check = np.array([0.0, 0.0, -2.5e-2, 0.0, -2.0e-2, 0.0]) assert np.allclose(v0, check), "FROM-MVR failed" - return - - -# - No need to change any code below - @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # run the test model - test.run_mf6(Simulation(exdir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - sim = Simulation(exdir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_ts_sfr02.py b/autotest/test_gwf_ts_sfr02.py index 6cf9220424a..3a8442c86d0 100644 --- a/autotest/test_gwf_ts_sfr02.py +++ b/autotest/test_gwf_ts_sfr02.py @@ -1,30 +1,14 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from flopy.utils.compare import eval_bud_diff +from framework import TestFramework +from simulation import TestSimulation paktest = "sfr" ex = ["ts_sfr02"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - -# run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None def get_model(ws, name, timeseries=False): @@ -537,7 +521,6 @@ def build_model(idx, dir): def eval_model(sim): print("evaluating model budgets...") - from budget_file_compare import eval_bud_diff # get ia/ja from binary grid file fname = f"{os.path.basename(sim.name)}.dis.grb" @@ -616,43 +599,18 @@ def eval_model(sim): check = np.array([-2.5e-2, 0.0, 0.0, 0.0, -2.0e-2, 0.0]) assert np.allclose(v0, check), "TO-MVR failed" - return - - -# - No need to change any code below - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_ts_uzf01.py b/autotest/test_gwf_ts_uzf01.py index 6714a31f637..4af7b20511f 100644 --- a/autotest/test_gwf_ts_uzf01.py +++ b/autotest/test_gwf_ts_uzf01.py @@ -1,30 +1,14 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from flopy.utils.compare import eval_bud_diff +from framework import TestFramework +from simulation import TestSimulation paktest = "uzf" ex = ["ts_uzf01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - -# run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None def get_model(ws, name, timeseries=False): @@ -664,7 +648,6 @@ def build_model(idx, dir): def eval_model(sim): print("evaluating model budgets...") - from budget_file_compare import eval_bud_diff # get ia/ja from binary grid file fname = f"{os.path.basename(sim.name)}.dis.grb" @@ -702,43 +685,18 @@ def eval_model(sim): fpth = os.path.join(sim.simpath, fname) eval_bud_diff(fpth, cobj0, cobj1) - return - - -# - No need to change any code below - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_utl01_binaryinput.py b/autotest/test_gwf_utl01_binaryinput.py index 0bf84dd7db6..a7ef3faef37 100644 --- a/autotest/test_gwf_utl01_binaryinput.py +++ b/autotest/test_gwf_utl01_binaryinput.py @@ -4,25 +4,13 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["binary01", "binary02"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -88,7 +76,7 @@ def build_model(idx, dir): # write top to a binary file text = "TOP" fname = "top.bin" - pth = os.path.join(exdirs[idx], fname) + pth = os.path.join(dir, fname) f = open(pth, "wb") header = flopy.utils.BinaryHeader.create( bintype="HEAD", @@ -123,7 +111,7 @@ def build_model(idx, dir): for k in range(nlay): text = f"BOTM_L{k + 1}" fname = f"botm.l{k + 1:02d}.bin" - pth = os.path.join(exdirs[idx], fname) + pth = os.path.join(dir, fname) f = open(pth, "wb") header = flopy.utils.BinaryHeader.create( bintype="HEAD", @@ -155,7 +143,7 @@ def build_model(idx, dir): ) elif idx == 1: fname = "botm.bin" - pth = os.path.join(exdirs[idx], fname) + pth = os.path.join(dir, fname) f = open(pth, "wb") tarr = np.ones((nlay, nrow, ncol), dtype=np.float64) for k in range(nlay): @@ -189,7 +177,7 @@ def build_model(idx, dir): for k in range(nlay): text = f"IDOMAIN_L{k + 1}" fname = f"idomain.l{k + 1:02d}.bin" - pth = os.path.join(exdirs[idx], fname) + pth = os.path.join(dir, fname) f = open(pth, "wb") header = flopy.utils.BinaryHeader.create( bintype="HEAD", @@ -221,7 +209,7 @@ def build_model(idx, dir): ) elif idx == 1: fname = "idomain.bin" - pth = os.path.join(exdirs[idx], fname) + pth = os.path.join(dir, fname) f = open(pth, "wb") header = flopy.utils.BinaryHeader.create( bintype="HEAD", @@ -270,7 +258,7 @@ def build_model(idx, dir): for k in range(nlay): text = f"IC_L{k + 1}" fname = f"ic.strt_l{k + 1:02d}.bin" - pth = os.path.join(exdirs[idx], fname) + pth = os.path.join(dir, fname) f = open(pth, "wb") header = flopy.utils.BinaryHeader.create( bintype="HEAD", @@ -302,7 +290,7 @@ def build_model(idx, dir): ) elif idx == 1: fname = "ic.strt.bin" - pth = os.path.join(exdirs[idx], fname) + pth = os.path.join(dir, fname) f = open(pth, "wb") header = flopy.utils.BinaryHeader.create( bintype="HEAD", @@ -339,7 +327,7 @@ def build_model(idx, dir): icelltype = [] for k in range(nlay): fname = f"npf.icelltype.l{k + 1}.bin" - pth = os.path.join(exdirs[idx], fname) + pth = os.path.join(dir, fname) f = open(pth, "wb") header = flopy.utils.BinaryHeader.create( bintype="head", @@ -372,7 +360,7 @@ def build_model(idx, dir): ) elif idx == 1: fname = "npf.icelltype.bin" - pth = os.path.join(exdirs[idx], fname) + pth = os.path.join(dir, fname) f = open(pth, "wb") header = flopy.utils.BinaryHeader.create( bintype="head", @@ -439,39 +427,12 @@ def build_model(idx, dir): return sim, None -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run(TestSimulation(name=name, exe_dict=targets), ws) diff --git a/autotest/test_gwf_utl02_timeseries.py b/autotest/test_gwf_utl02_timeseries.py index 573c2989f0e..3f06e46042a 100644 --- a/autotest/test_gwf_utl02_timeseries.py +++ b/autotest/test_gwf_utl02_timeseries.py @@ -1,24 +1,9 @@ -import os - -import numpy as np +import flopy import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["ts01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -163,39 +148,12 @@ def build_model(idx, dir): return sim, None -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run(TestSimulation(name=name, exe_dict=targets), ws) diff --git a/autotest/test_gwf_utl03_obs01.py b/autotest/test_gwf_utl03_obs01.py index 4f5944833a6..a8df98865b0 100644 --- a/autotest/test_gwf_utl03_obs01.py +++ b/autotest/test_gwf_utl03_obs01.py @@ -1,25 +1,12 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["utl03_obs"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" # temporal discretization nper = 2 @@ -61,12 +48,12 @@ hclose, rclose, relax = 1e-6, 0.01, 1.0 -def build_mf6(idx, ws, binaryobs=True): +def build_mf6(idx, ws, exe, binaryobs=True): name = ex[idx] # build MODFLOW 6 files sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws + sim_name=name, version="mf6", exe_name=exe, sim_ws=ws ) # create tdis package flopy.mf6.ModflowTdis( @@ -150,21 +137,25 @@ def build_mf6(idx, ws, binaryobs=True): return sim -def build_model(idx, dir): +def build_model(idx, dir, exe): ws = dir # build mf6 with ascii observation output - sim = build_mf6(idx, ws, binaryobs=False) + sim = build_mf6(idx, ws, exe=exe, binaryobs=False) # build mf6 with binary observation output wsc = os.path.join(ws, "mf6") - mc = build_mf6(idx, wsc, binaryobs=True) + mc = build_mf6(idx, wsc, exe=exe, binaryobs=True) + + sim.write_simulation() + mc.write_simulation() + hack_binary_obs(idx, dir) return sim, mc -def build_models(): - for idx, dir in enumerate(exdirs): - sim, mc = build_model(idx, dir) +def build_models(dir, exe): + for idx, name in enumerate(ex): + sim, mc = build_model(idx, dir, exe) sim.write_simulation() mc.write_simulation() hack_binary_obs(idx, dir) @@ -224,41 +215,14 @@ def eval_obs(sim): ) assert np.allclose(d0[name], d1[name], rtol=1e-5), msg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - build_models() - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_obs)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - build_models() - - # run the test model - for dir in exdirs: - sim = Simulation(dir, exfunc=eval_obs) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + mf6 = targets["mf6"] + test = TestFramework() + build_models(ws, mf6) + test.run(TestSimulation(name=name, exe_dict=targets, exfunc=eval_obs), ws) diff --git a/autotest/test_gwf_utl04_auxmult.py b/autotest/test_gwf_utl04_auxmult.py index 9c925f36336..78ae0f8f55d 100644 --- a/autotest/test_gwf_utl04_auxmult.py +++ b/autotest/test_gwf_utl04_auxmult.py @@ -6,25 +6,13 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["auxmult01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -191,39 +179,15 @@ def eval_model(sim): # assert False - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation(name=name, exe_dict=targets, exfunc=eval_model), ws + ) diff --git a/autotest/test_gwf_utl05_budparse.py b/autotest/test_gwf_utl05_budparse.py index d62d7f74ed2..216413bf199 100644 --- a/autotest/test_gwf_utl05_budparse.py +++ b/autotest/test_gwf_utl05_budparse.py @@ -5,36 +5,16 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwf_utl05"] laytyp = [1] ss = [1.0e-10] sy = [0.1] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" nlay, nrow, ncol = 1, 1, 1 @@ -164,8 +144,7 @@ def build_model(idx, dir): def eval_flow(sim): print("evaluating flow...") - name = ex[sim.idxsim] - gwfname = "gwf_" + name + gwfname = "gwf_" + sim.name # This will fail if budget numbers cannot be read fpth = os.path.join(sim.simpath, f"{gwfname}.lst") @@ -180,36 +159,17 @@ def eval_flow(sim): assert np.allclose(inc["WEL_OUT"], 0.0) -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_flow, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_flow, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_flow, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwf_utl06_tas.py b/autotest/test_gwf_utl06_tas.py index 0f5b3bd8e05..dbde41bec9a 100644 --- a/autotest/test_gwf_utl06_tas.py +++ b/autotest/test_gwf_utl06_tas.py @@ -6,19 +6,11 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = [ "utl06_tas_a", @@ -26,9 +18,6 @@ "utl06_tas_c", "utl06_tas_d", ] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) nlay, nrow, ncol = 3, 5, 5 idomain_lay0 = [ @@ -375,42 +364,18 @@ def eval_transport(sim): qa = [a * rate * frac for a, rate in zip(area, id2a)] assert np.allclose(q, qa), f"{q} /=\n {qa}" - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_uzf01.py b/autotest/test_gwf_uzf01.py index 1fcbc24890c..0d168da3265 100644 --- a/autotest/test_gwf_uzf01.py +++ b/autotest/test_gwf_uzf01.py @@ -6,33 +6,13 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwf_uzf01a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" nlay, nrow, ncol = 100, 1, 1 @@ -236,8 +216,8 @@ def build_model(idx, exdir): def eval_flow(sim): print("evaluating flow...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath # check binary grid file fname = os.path.join(ws, name + ".dis.grb") @@ -281,41 +261,18 @@ def eval_flow(sim): "data in the cell-by-cell file." ) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # run the test model - test.run_mf6(Simulation(exdir, exfunc=eval_flow, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - sim = Simulation(exdir, exfunc=eval_flow, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_flow, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_uzf02.py b/autotest/test_gwf_uzf02.py index 0e0eed7dc40..03996c8efe6 100644 --- a/autotest/test_gwf_uzf02.py +++ b/autotest/test_gwf_uzf02.py @@ -5,33 +5,13 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwf_uzf02a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" nlay, nrow, ncol = 1, 1, 1 @@ -248,9 +228,6 @@ def build_model(idx, dir): def make_plot(sim, obsvals): print("making plots...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] - # shows curves for times 2.5, 7.5, 12.6, 17.7 # which are indices 24, 74, 125, and -1 idx = [24, 74, 125, -1] @@ -276,17 +253,15 @@ def make_plot(sim, obsvals): plt.legend() fname = "fig-xsect.pdf" - fname = os.path.join(ws, fname) + fname = os.path.join(sim.simpath, fname) plt.savefig(fname, bbox_inches="tight") - return - def eval_flow(sim): print("evaluating flow...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath # check binary grid file fname = os.path.join(ws, name + ".dis.grb") @@ -330,41 +305,19 @@ def eval_flow(sim): assert False, f'could not load data from "{fpth}"' if False: make_plot(sim, obsvals) - return -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_flow, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_flow, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_flow, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwf_uzf03.py b/autotest/test_gwf_uzf03.py index cbcad1e6dbf..361036a4c01 100644 --- a/autotest/test_gwf_uzf03.py +++ b/autotest/test_gwf_uzf03.py @@ -6,38 +6,17 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwf_uzf03a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" nlay, nrow, ncol = 15, 1, 1 def build_model(idx, dir): - perlen = [17.7] nper = len(perlen) nstp = [177] @@ -250,9 +229,6 @@ def build_model(idx, dir): def make_plot(sim, obsvals): print("making plots...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] - # shows curves for times 2.5, 7.5, 12.6, 17.7 # which are indices 24, 74, 125, and -1 idx = [24, 74, 125, -1] @@ -277,17 +253,15 @@ def make_plot(sim, obsvals): plt.legend() fname = "fig-xsect.pdf" - fname = os.path.join(ws, fname) + fname = os.path.join(sim.simpath, fname) plt.savefig(fname, bbox_inches="tight") - return - def eval_flow(sim): print("evaluating flow...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath # check binary grid file fname = os.path.join(ws, name + ".dis.grb") @@ -331,41 +305,19 @@ def eval_flow(sim): assert False, f'could not load data from "{fpth}"' if False: make_plot(sim, obsvals) - return -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_flow, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_flow, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_flow, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwf_uzf04.py b/autotest/test_gwf_uzf04.py index 05ea7f8025d..4662ea98e2d 100644 --- a/autotest/test_gwf_uzf04.py +++ b/autotest/test_gwf_uzf04.py @@ -11,35 +11,14 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwf_uzf04a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" nlay, nrow, ncol = 1, 1, 1 - thts = 0.30 # saturated water content thtr = 0.05 # residual water content thti = 0.10 # initial water content @@ -239,8 +218,8 @@ def build_model(idx, dir): def eval_flow(sim): print("evaluating flow...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath fname = os.path.join(ws, f"{name}.uzf.bin") wobj = flopy.utils.HeadFile(fname, text="WATER-CONTENT") @@ -277,41 +256,18 @@ def eval_flow(sim): vw, volume_mobile_sim ), "Simulated mobile water volume in aux does not match known result" - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_flow, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_flow, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_flow, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_uzf05.py b/autotest/test_gwf_uzf05.py index 7258a5a03cf..457ffd8b7b8 100644 --- a/autotest/test_gwf_uzf05.py +++ b/autotest/test_gwf_uzf05.py @@ -7,33 +7,13 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwf_uzf05a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" nlay, nrow, ncol = 3, 1, 1 thts = 0.30 # saturated water content @@ -59,7 +39,7 @@ def build_model(idx, dir): # unsat props hk = 10.0 - infiltration_rate = 10. + infiltration_rate = 10.0 evapotranspiration_rate = 0.0 evt_extinction_depth = 2.0 brooks_corey_epsilon = 3.5 # brooks corey exponent @@ -237,8 +217,8 @@ def build_model(idx, dir): def eval_flow(sim): print("evaluating flow...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath fname = os.path.join(ws, f"{name}.uzf.bin") wobj = flopy.utils.HeadFile(fname, text="WATER-CONTENT") @@ -256,43 +236,20 @@ def eval_flow(sim): node, node2, q, flow_area = flowtogwf[0] assert node == 1, "uzf node should be 1" assert node2 == 1, "GWF node should be 1" - assert np.isclose(q, -4.), "Flow from UZF to node 1 should be -4." - - return + assert np.isclose(q, -4.0), "Flow from UZF to node 1 should be -4." -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_flow, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_flow, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_flow, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_uzf_gwet.py b/autotest/test_gwf_uzf_gwet.py index 171d984a903..ab7d74556d8 100644 --- a/autotest/test_gwf_uzf_gwet.py +++ b/autotest/test_gwf_uzf_gwet.py @@ -1,34 +1,14 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["uzf_3lay"] -exdirs = [] iuz_cell_dict = {} cell_iuz_dict = {} -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -280,8 +260,7 @@ def build_model(idx, dir): def eval_model(sim): print("evaluating model...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + ws = sim.simpath sim = flopy.mf6.MFSimulation.load(sim_ws=ws) fpth = os.path.join(ws, "uzf_3lay.hds") @@ -391,36 +370,14 @@ def eval_model(sim): print("Finished running checks") -# - No need to change any code below -@pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), -) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_model, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_model, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +@pytest.mark.parametrize("name", ex) +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_model, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwf_uzf_surfdep.py b/autotest/test_gwf_uzf_surfdep.py index b9d101fd682..824727a9fff 100644 --- a/autotest/test_gwf_uzf_surfdep.py +++ b/autotest/test_gwf_uzf_surfdep.py @@ -1,40 +1,12 @@ -import os -import shutil -import subprocess -import sys - -import numpy as np -import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -import targets - -mf6_exe = os.path.abspath(targets.target_dict["mf6"]) +import flopy + testname = "uzf_3lay_srfdchk" -testdir = os.path.join("temp", testname) -os.makedirs(testdir, exist_ok=True) -everything_was_successful = True iuz_cell_dict = {} cell_iuz_dict = {} -def build_model(): +def build_model(dir, exe): nlay, nrow, ncol = 3, 1, 10 nper = 1 @@ -61,9 +33,9 @@ def build_model(): name = testname # build MODFLOW 6 files - ws = testdir + ws = dir sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name=mf6_exe, sim_ws=ws + sim_name=name, version="mf6", exe_name=exe, sim_ws=ws ) # create tdis package @@ -213,15 +185,15 @@ def build_model(): return sim -# - No need to change any code below -def test_mf6model(): +def test_mf6model(function_tmpdir, targets): # build and run the test model - sim = build_model() + mf6 = targets.mf6 + sim = build_model(str(function_tmpdir), mf6) sim.write_simulation() sim.run_simulation() # ensure that the error msg is contained in the mfsim.lst file - f = open(os.path.join(testdir, "mfsim.lst"), "r") + f = open(str(function_tmpdir / "mfsim.lst"), "r") lines = f.readlines() error_count = 0 expected_msg = False @@ -235,21 +207,3 @@ def test_mf6model(): ) print("Finished running surfdep check") - - shutil.rmtree(testdir, ignore_errors=True) - - return - - -def main(): - test_mf6model() - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_uzf_wc_output.py b/autotest/test_gwf_uzf_wc_output.py index 1404ca4b21f..bd43193ace4 100644 --- a/autotest/test_gwf_uzf_wc_output.py +++ b/autotest/test_gwf_uzf_wc_output.py @@ -1,33 +1,15 @@ import os +import flopy +import flopy.utils.binaryfile as bf import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -import flopy.utils.binaryfile as bf - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation include_NWT = False ex = ["uzf_3lay_wc_chk"] -exdirs = [os.path.join("temp", name) for name in ex] iuz_cell_dict = {} cell_iuz_dict = {} @@ -470,9 +452,8 @@ def build_model(idx, ws): def eval_model(sim): print("evaluating model...") - idx = sim.idxsim - name = ex[idx] - ws = os.path.join("temp", name) + name = sim.name + ws = sim.simpath # Get the MF6 heads fpth = os.path.join(ws, "uzf_3lay_wc_chk.hds") @@ -560,39 +541,20 @@ def eval_model(sim): print("Finished running checks") -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # run the test models - test.run_mf6( - Simulation( - exdir, +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, + exe_dict=targets, exfunc=eval_model, - idxsim=idx, - ) + idxsim=0, + ), + ws, ) - return - - -def main(): - for idx, exdir in enumerate(exdirs): - test_mf6model(idx, exdir) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/autotest/test_gwf_vsc01.py b/autotest/test_gwf_vsc01.py index 0c547db2e77..5b27cebda76 100644 --- a/autotest/test_gwf_vsc01.py +++ b/autotest/test_gwf_vsc01.py @@ -11,27 +11,16 @@ import os import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation hyd_cond = [1205.49396942506, 864.0] # Hydraulic conductivity (m/d) ex = ["no-vsc01-bnd", "vsc01-bnd", "no-vsc01-k"] viscosity_on = [False, True, False] hydraulic_conductivity = [hyd_cond[0], hyd_cond[1], hyd_cond[1]] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # Model units @@ -287,7 +276,7 @@ def eval_results(sim): # Ensure latest simulated value hasn't changed from stored answer assert np.allclose( sim_val_1, stored_ans, atol=1e-4 - ), "Flow in the " + exdirs[ + ), "Flow in the " + ex[ 0 ] + " test problem (doesn't simulate " "viscosity) has changed,\n should be " + str( stored_ans @@ -302,7 +291,7 @@ def eval_results(sim): # Ensure latest simulated value hasn't changed from stored answer assert np.allclose( sim_val_2, stored_ans, atol=1e-4 - ), "Flow in the " + exdirs[ + ), "Flow in the " + ex[ 1 ] + " test problem (simulates " "viscosity) has changed,\n should be " + str( stored_ans @@ -317,43 +306,25 @@ def eval_results(sim): # Ensure the flow leaving model 3 is less than what leaves model 2 assert abs(stored_ans) > abs(sim_val_3), ( "Exit flow from model " - + exdirs[1] + + ex[1] + " should be greater than flow exiting " - + exdirs[2] + + ex[2] + ", but it is not." ) # - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_vsc02.py b/autotest/test_gwf_vsc02.py index 2e6039d5116..a3fb061646e 100644 --- a/autotest/test_gwf_vsc02.py +++ b/autotest/test_gwf_vsc02.py @@ -12,29 +12,17 @@ import os import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -# Import common functionality -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation # Setup scenario input hyd_cond = [1205.49396942506, 864.0] # Hydraulic conductivity (m/d) ex = ["no-vsc02-bnd", "vsc02-bnd", "no-vsc02-k"] viscosity_on = [False, True, False] hydraulic_conductivity = [hyd_cond[0], hyd_cond[1], hyd_cond[1]] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # Model units @@ -291,7 +279,7 @@ def eval_results(sim): # Ensure latest simulated value hasn't changed from stored answer assert np.allclose( sim_val_1, stored_ans, atol=1e-4 - ), "Flow in the " + exdirs[ + ), "Flow in the " + ex[ 0 ] + " test problem (doesn't simulate " "viscosity) has changed,\n should be " + str( stored_ans @@ -306,7 +294,7 @@ def eval_results(sim): # Ensure latest simulated value hasn't changed from stored answer assert np.allclose( sim_val_2, stored_ans, atol=1e-4 - ), "Flow in the " + exdirs[ + ), "Flow in the " + ex[ 1 ] + " test problem (simulates " "viscosity) has changed,\n should be " + str( stored_ans @@ -321,43 +309,24 @@ def eval_results(sim): # Ensure the flow leaving model 3 is less than what leaves model 2 assert abs(stored_ans) > abs(sim_val_3), ( "Exit flow from model " - + exdirs[1] + + ex[1] + " should be greater than flow existing " - + exdirs[2] + + ex[2] + ", but it is not." ) -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_vsc03_sfr.py b/autotest/test_gwf_vsc03_sfr.py index a3c79f0620b..97e0148e148 100644 --- a/autotest/test_gwf_vsc03_sfr.py +++ b/autotest/test_gwf_vsc03_sfr.py @@ -12,25 +12,14 @@ import os import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["no-vsc-sfr01", "vsc-sfr01"] viscosity_on = [False, True] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # Equation for determining land surface elevation with a stream running down the middle def topElev_sfrCentered(x, y): @@ -541,36 +530,17 @@ def eval_results(sim): ) -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_vsc04_lak.py b/autotest/test_gwf_vsc04_lak.py index 54757eca6e5..912b2772f5e 100644 --- a/autotest/test_gwf_vsc04_lak.py +++ b/autotest/test_gwf_vsc04_lak.py @@ -14,27 +14,15 @@ # import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["no-vsc04-lak", "vsc04-lak"] viscosity_on = [False, True] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # Model units length_units = "m" @@ -174,11 +162,10 @@ # -def build_model(idx, dir): +def build_model(idx, ws): global lak_lkup_dict # Base simulation and model name and workspace - ws = dir name = ex[idx] print("Building model...{}".format(name)) @@ -787,36 +774,17 @@ def eval_results(sim): ) -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_vsc05_hfb.py b/autotest/test_gwf_vsc05_hfb.py index 6846226fd78..490139b73e6 100644 --- a/autotest/test_gwf_vsc05_hfb.py +++ b/autotest/test_gwf_vsc05_hfb.py @@ -23,27 +23,16 @@ import os import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation hyd_cond = [1205.49396942506, 864.0] # Hydraulic conductivity (m/d) ex = ["no-vsc05-hfb", "vsc05-hfb", "no-vsc05-k"] viscosity_on = [False, True, False] hydraulic_conductivity = [hyd_cond[0], hyd_cond[1], hyd_cond[1]] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # Model units @@ -350,7 +339,7 @@ def eval_results(sim): no_vsc_bud_last[:, 2], stored_ans[:, 2], atol=1e-3 ), ( "Flow in models " - + exdirs[0] + + ex[0] + " and the established answer should be approximately " "equal, but are not." ) @@ -362,7 +351,7 @@ def eval_results(sim): with_vsc_bud_last[:, 2], stored_ans[:, 2], atol=1e-3 ), ( "Flow in models " - + exdirs[1] + + ex[1] + " and the established answer should be approximately " "equal, but are not." ) @@ -375,41 +364,23 @@ def eval_results(sim): assert np.less(no_vsc_low_k_bud_last[:, 2], stored_ans[:, 2]).all(), ( "Exit flow from model the established answer " "should be greater than flow existing " - + exdirs[2] + + ex[2] + ", but it is not." ) # - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_wel01.py b/autotest/test_gwf_wel01.py index c6923112ccc..719504765b5 100644 --- a/autotest/test_gwf_wel01.py +++ b/autotest/test_gwf_wel01.py @@ -5,33 +5,13 @@ """ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["wel01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" # set static data nper = 1 @@ -201,39 +181,18 @@ def eval_obs(sim): errmsg += f"{a1} /= {a2}" assert np.allclose(a1, a2), errmsg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_obs, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_obs, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_obs, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwf_zb01.py b/autotest/test_gwf_zb01.py index 36fa5c8ca83..a408e2b7b7b 100644 --- a/autotest/test_gwf_zb01.py +++ b/autotest/test_gwf_zb01.py @@ -1,37 +1,15 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -import targets -from framework import running_on_CI, testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["zbud6_zb01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - -ddir = "data" - -## run all examples on Travis -continuous_integration = [True for idx in range(len(exdirs))] - -# set replace_exe to None to use default executable -replace_exe = None - -htol = [None for idx in range(len(exdirs))] +htol = [None for idx in range(len(ex))] dtol = 1e-3 budtol = 1e-2 - bud_lst = [ "STO-SS_IN", "STO-SS_OUT", @@ -132,13 +110,13 @@ # variant SUB package problem 3 -def build_model(idx, dir): +def build_model(idx, dir, exe): name = ex[idx] # build MODFLOW 6 files ws = dir sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws + sim_name=name, version="mf6", exe_name=exe, sim_ws=ws ) # create tdis package tdis = flopy.mf6.ModflowTdis( @@ -238,8 +216,7 @@ def build_model(idx, dir): return sim, None -def eval_zb6(sim): - +def eval_zb6(sim, exe): print("evaluating zonebudget...") # build zonebudget files @@ -267,21 +244,18 @@ def eval_zb6(sim): f.close() # run zonebudget - zbexe = os.path.abspath(targets.target_dict["zbud6"]) success, buff = flopy.run_model( - zbexe, + exe, "zonebudget.nam", model_ws=sim.simpath, silent=False, report=True, ) if success: - print(f"successfully ran...{os.path.basename(zbexe)}") sim.success = True else: sim.success = False - msg = f"could not run...{zbexe}" - assert success, msg + assert success # read data from csv file fpth = os.path.join(sim.simpath, "zonebudget.csv") @@ -414,62 +388,24 @@ def eval_zb6(sim): sim.success = True print(" " + msg) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - - # determine if running on CI infrastructure - is_CI = running_on_CI() - r_exe = None - if not is_CI: - if replace_exe is not None: - r_exe = replace_exe - - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models_legacy(build_model, idx, dir) - - # run the test model - if is_CI and not continuous_integration[idx]: - return - test.run_mf6( - Simulation( - dir, exfunc=eval_zb6, exe_dict=r_exe, htol=htol[idx], idxsim=idx - ) - ) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models_legacy(build_model, idx, dir) - sim = Simulation( - dir, - exfunc=eval_zb6, - exe_dict=replace_exe, +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + mf6 = targets.mf6 + zb6 = targets.zbud6 + test = TestFramework() + test.build(lambda i, w: build_model(i, w, mf6), idx, ws) + test.run( + TestSimulation( + name=name, + exe_dict=targets, + exfunc=lambda s: eval_zb6(s, zb6), htol=htol[idx], idxsim=idx, - ) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() + ), + ws, + ) diff --git a/autotest/test_gwfgwf_lgr.py b/autotest/test_gwfgwf_lgr.py index 74b94a63d69..7404f10805b 100644 --- a/autotest/test_gwfgwf_lgr.py +++ b/autotest/test_gwfgwf_lgr.py @@ -32,27 +32,15 @@ """ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - from flopy.utils.lgrutil import Lgr - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwfgwf_lgr_classic", "gwfgwf_lgr_ifmod"] ifmod = [False, True] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) parent_name = "parent" child_name = "child" @@ -287,41 +275,18 @@ def eval_heads(sim): errmsg = f"min or max residual too large {res.min()} {res.max()}" assert np.allclose(res, 0.0, atol=1.0e-6), errmsg - return - @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -@pytest.mark.developmode -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # run the test model - test.run_mf6(Simulation(exdir, exfunc=eval_heads, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - - sim = Simulation(exdir, exfunc=eval_heads, idxsim=idx) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_heads, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_adv01.py b/autotest/test_gwt_adv01.py index 3afcf22e605..7132f16d38e 100644 --- a/autotest/test_gwt_adv01.py +++ b/autotest/test_gwt_adv01.py @@ -6,28 +6,15 @@ """ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["adv01a", "adv01b", "adv01c"] scheme = ["upstream", "central", "tvd"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -601,42 +588,18 @@ def eval_transport(sim): creslist[sim.idxsim], conc ), "simulated concentrations do not match with known solution." - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_adv01_fmi.py b/autotest/test_gwt_adv01_fmi.py index 98a08712210..84faee0f9a0 100644 --- a/autotest/test_gwt_adv01_fmi.py +++ b/autotest/test_gwt_adv01_fmi.py @@ -6,29 +6,17 @@ """ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from binary_file_writer import uniform_flow_field, write_budget, write_head -from framework import testing_framework -from simulation import Simulation +from flopy.utils.binaryfile import write_budget, write_head +from flopy.utils.gridutil import uniform_flow_field +from framework import TestFramework +from simulation import TestSimulation ex = ["adv01a_fmi", "adv01b_fmi", "adv01c_fmi"] scheme = ["upstream", "central", "tvd"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -576,42 +564,18 @@ def eval_transport(sim): creslist[sim.idxsim], conc ), "simulated concentrations do not match with known solution." - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_adv01_gwtgwt.py b/autotest/test_gwt_adv01_gwtgwt.py index 42c47128abf..ed325110506 100644 --- a/autotest/test_gwt_adv01_gwtgwt.py +++ b/autotest/test_gwt_adv01_gwtgwt.py @@ -7,28 +7,14 @@ import os +import flopy import numpy as np import pytest -from matplotlib import pyplot as plt - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["adv01a_gwtgwt", "adv01b_gwtgwt", "adv01c_gwtgwt"] scheme = ["upstream", "central", "tvd"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - gdelr = 1.0 @@ -739,43 +725,18 @@ def eval_transport(sim): # TODO: this is not implemented yet: # assert np.allclose(res, 0.0, atol=1.0e-6), errmsg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -@pytest.mark.developmode -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_adv02.py b/autotest/test_gwt_adv02.py index 39942b02189..4d0a5ba635b 100644 --- a/autotest/test_gwt_adv02.py +++ b/autotest/test_gwt_adv02.py @@ -8,29 +8,16 @@ """ import os -import sys +import flopy +import flopy.utils.cvfdutil import numpy as np import pytest - -try: - import flopy - import flopy.utils.cvfdutil -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["adv02a", "adv02b", "adv02c"] scheme = ["upstream", "central", "tvd"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def grid_triangulator(itri, delr, delc): @@ -954,42 +941,18 @@ def eval_transport(sim): creslist[sim.idxsim], conc ), "simulated concentrations do not match with known solution." - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_adv03.py b/autotest/test_gwt_adv03.py index db6014f586d..5134fe038f7 100644 --- a/autotest/test_gwt_adv03.py +++ b/autotest/test_gwt_adv03.py @@ -8,29 +8,16 @@ """ import os -import sys +import flopy +import flopy.utils.cvfdutil import numpy as np import pytest - -try: - import flopy - import flopy.utils.cvfdutil -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["adv03a", "adv03b", "adv03c"] scheme = ["upstream", "central", "tvd"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def grid_triangulator(itri, delr, delc): @@ -506,42 +493,18 @@ def eval_transport(sim): conc[0, 0, -ncellsperrow:], ) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_adv04.py b/autotest/test_gwt_adv04.py index 9bb743fe91d..49c1ca45690 100644 --- a/autotest/test_gwt_adv04.py +++ b/autotest/test_gwt_adv04.py @@ -7,36 +7,15 @@ """ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["adv04a", "adv04b", "adv04c"] scheme = ["upstream", "central", "tvd"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -277,44 +256,18 @@ def eval_transport(sim): "symmetric in left-right direction." ) - return - - -# - No need to change any code below - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_buy_solute_heat.py b/autotest/test_gwt_buy_solute_heat.py index b1a7f0b818a..173dfd60b04 100644 --- a/autotest/test_gwt_buy_solute_heat.py +++ b/autotest/test_gwt_buy_solute_heat.py @@ -1,24 +1,12 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["gwtbuy"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -342,8 +330,8 @@ def build_model(idx, dir): def make_plot(sim): print("making plots...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath sim = flopy.mf6.MFSimulation.load(sim_ws=ws) gwfname = "flow" gwtsname = "salinity" @@ -429,7 +417,6 @@ def eval_transport(sim): if makeplot: make_plot(sim) - name = ex[sim.idxsim] ws = sim.simpath gwfname = "flow" gwtsname = "salinity" @@ -473,44 +460,19 @@ def eval_transport(sim): np.savetxt(fname, densecalculated.reshape(200, 100)) assert False, "density is not correct" - # assert False - - return - -# - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_disu01.py b/autotest/test_gwt_disu01.py index 45e33a5602e..a9aad3dfdf6 100644 --- a/autotest/test_gwt_disu01.py +++ b/autotest/test_gwt_disu01.py @@ -7,41 +7,18 @@ """ import os -import sys +import flopy import numpy as np import pytest +from flopy.utils.gridutil import get_disu_kwargs +from framework import TestFramework +from simulation import TestSimulation -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from disu_util import get_disu_kwargs -from framework import testing_framework -from simulation import Simulation - -ex = [ - "disu01a", -] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - - -def build_model(idx, dir): +ex = ["disu01a"] + + +def build_model(idx, dir, exe): nlay, nrow, ncol = 1, 21, 21 nper = 1 perlen = [5.0] @@ -87,7 +64,7 @@ def get_nn(k, i, j): # build MODFLOW 6 files ws = dir sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws + sim_name=name, version="mf6", exe_name=exe, sim_ws=ws ) # create tdis package tdis = flopy.mf6.ModflowTdis( @@ -246,7 +223,7 @@ def get_nn(k, i, j): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") @@ -272,44 +249,19 @@ def eval_transport(sim): "symmetric in left-right direction." ) - return - - -# - No need to change any code below - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + mf6 = targets.mf6 + test = TestFramework() + test.build(lambda i, w: build_model(i, w, mf6), 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_dsp01.py b/autotest/test_gwt_dsp01.py index ad11fc51c19..7d392cb225d 100644 --- a/autotest/test_gwt_dsp01.py +++ b/autotest/test_gwt_dsp01.py @@ -1,34 +1,13 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["dsp01a", "dsp01b"] xt3d = [False, True] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -406,42 +385,18 @@ def eval_transport(sim): # comment when done testing # assert False - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_dsp01_fmi.py b/autotest/test_gwt_dsp01_fmi.py index 10a7e5c5189..424d467a702 100644 --- a/autotest/test_gwt_dsp01_fmi.py +++ b/autotest/test_gwt_dsp01_fmi.py @@ -1,35 +1,14 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from binary_file_writer import write_budget, write_head -from framework import testing_framework -from simulation import Simulation +from flopy.utils.binaryfile import write_budget, write_head +from framework import TestFramework +from simulation import TestSimulation ex = ["dsp01a_fmi", "dsp01b_fmi"] xt3d = [False, True] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -340,42 +319,18 @@ def eval_transport(sim): cres, conc ), "simulated concentrations do not match with known solution." - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_dsp01_gwtgwt.py b/autotest/test_gwt_dsp01_gwtgwt.py index d7d01e6fe05..156269c0e05 100644 --- a/autotest/test_gwt_dsp01_gwtgwt.py +++ b/autotest/test_gwt_dsp01_gwtgwt.py @@ -6,27 +6,13 @@ import os +import flopy import numpy as np import pytest -from matplotlib import pyplot as plt - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["dsp01_gwtgwt"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" - gdelr = 1.0 @@ -311,43 +297,18 @@ def eval_transport(sim): # no loss of solute assert abs(np.sum(conc1) + np.sum(conc2) - 100.0) < 1e-6 - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -@pytest.mark.developmode -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_dsp01_noadv.py b/autotest/test_gwt_dsp01_noadv.py index 230d3711752..b5864f0bb19 100644 --- a/autotest/test_gwt_dsp01_noadv.py +++ b/autotest/test_gwt_dsp01_noadv.py @@ -1,34 +1,13 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["dsp01a_noadv", "dsp01b_noadv"] xt3d = [False, True] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -284,42 +263,18 @@ def eval_transport(sim): cres, conc ), "simulated concentrations do not match with known solution." - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_dsp02.py b/autotest/test_gwt_dsp02.py index d2e0d7f0613..0b245e78058 100644 --- a/autotest/test_gwt_dsp02.py +++ b/autotest/test_gwt_dsp02.py @@ -8,29 +8,16 @@ """ import os -import sys +import flopy +import flopy.utils.cvfdutil import numpy as np import pytest - -try: - import flopy - import flopy.utils.cvfdutil -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["dsp02a", "dsp02b"] xt3d = [True, False] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def grid_triangulator(itri, delr, delc): @@ -725,42 +712,18 @@ def eval_transport(sim): creslist[sim.idxsim], conc ), "simulated concentrations do not match with known solution." - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_dsp03.py b/autotest/test_gwt_dsp03.py index 960de6fe324..7eb77075c88 100644 --- a/autotest/test_gwt_dsp03.py +++ b/autotest/test_gwt_dsp03.py @@ -8,29 +8,16 @@ """ import os -import sys +import flopy +import flopy.utils.cvfdutil import numpy as np import pytest - -try: - import flopy - import flopy.utils.cvfdutil -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["dsp03a", "dsp03b"] xt3d = [False, True] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def grid_triangulator(itri, delr, delc): @@ -451,42 +438,19 @@ def eval_transport(sim): conc[0, 0, -ncellsperrow:], ) - return - -# - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_dsp04.py b/autotest/test_gwt_dsp04.py index 85724e4856d..aa9d1b02206 100644 --- a/autotest/test_gwt_dsp04.py +++ b/autotest/test_gwt_dsp04.py @@ -1,35 +1,14 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation # test dispersion without and with xt3d ex = ["dsp04a", "dsp04b"] xt3d = [None, True] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -271,44 +250,18 @@ def eval_transport(sim): "symmetric in left-right direction." ) - return - - -# - No need to change any code below - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_dsp05_noadv.py b/autotest/test_gwt_dsp05_noadv.py index a5852b2132e..93af5361d4d 100644 --- a/autotest/test_gwt_dsp05_noadv.py +++ b/autotest/test_gwt_dsp05_noadv.py @@ -7,34 +7,14 @@ """ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["dsp05a_noadv", "dsp01b_noadv"] xt3d = [False, True] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -180,42 +160,18 @@ def eval_transport(sim): msg = f"simulated concentrations do not match with known solution. {conc} {cres}" assert np.allclose(cres, conc.flatten()), msg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_fmi01.py b/autotest/test_gwt_fmi01.py index 52d4c3680f6..fcf6a9e0251 100644 --- a/autotest/test_gwt_fmi01.py +++ b/autotest/test_gwt_fmi01.py @@ -1,37 +1,15 @@ import os -import sys +import flopy import numpy as np import pytest +from flopy.utils.binaryfile import write_budget, write_head +from flopy.utils.gridutil import uniform_flow_field +from framework import TestFramework +from simulation import TestSimulation -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from binary_file_writer import uniform_flow_field, write_budget, write_head -from framework import testing_framework -from simulation import Simulation - -ex = [ - "fmi01a_fc", -] +ex = ["fmi01a_fc"] xt3d = [False, True] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -198,17 +176,12 @@ def build_model(idx, dir): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") - try: - cobj = flopy.utils.HeadFile( - fpth, precision="double", text="CONCENTRATION" - ) - conc = cobj.get_data() - except: - assert False, f'could not load data from "{fpth}"' + cobj = flopy.utils.HeadFile(fpth, precision="double", text="CONCENTRATION") + conc = cobj.get_data() # This is the answer to this problem. Concentration should not change cres = [[[10, 10, 10]]] @@ -217,42 +190,18 @@ def eval_transport(sim): errmsg += f"cres: {cres}\ncans:{conc}" assert np.allclose(cres, conc), errmsg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_fmi02.py b/autotest/test_gwt_fmi02.py index 032d47b309f..545428e55e9 100644 --- a/autotest/test_gwt_fmi02.py +++ b/autotest/test_gwt_fmi02.py @@ -1,45 +1,16 @@ # tests to ability to run flow model first followed by transport model import os -import shutil -import numpy as np -import pytest +import flopy -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - - -import targets - -exe_name_mf6 = targets.target_dict["mf6"] -exe_name_mf6 = os.path.abspath(exe_name_mf6) -testdir = "./temp" testgroup = "fmi02" -d = os.path.join(testdir, testgroup) -if os.path.isdir(d): - shutil.rmtree(d) -def run_flow_model(): +def run_flow_model(dir, exe): name = "flow" - ws = os.path.join(testdir, testgroup, name) - sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=ws, exe_name=exe_name_mf6 - ) + ws = os.path.join(dir, testgroup, name) + sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=ws, exe_name=exe) pd = [(1.0, 1, 1.0), (1.0, 1, 1.0)] tdis = flopy.mf6.ModflowTdis(sim, nper=len(pd), perioddata=pd) ims = flopy.mf6.ModflowIms(sim) @@ -70,15 +41,12 @@ def run_flow_model(): assert os.path.isfile(fname) fname = os.path.join(ws, head_file) assert os.path.isfile(fname) - return -def run_transport_model(): +def run_transport_model(dir, exe): name = "transport" - ws = os.path.join(testdir, testgroup, name) - sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=ws, exe_name=exe_name_mf6 - ) + ws = os.path.join(dir, testgroup, name) + sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=ws, exe_name=exe) pd = [(1.0, 10, 1.0), (1.0, 10, 1.0)] tdis = flopy.mf6.ModflowTdis(sim, nper=len(pd), perioddata=pd) ims = flopy.mf6.ModflowIms(sim, linear_acceleration="BICGSTAB") @@ -106,21 +74,9 @@ def run_transport_model(): assert os.path.isfile(fname) fname = os.path.join(ws, concentration_file) assert os.path.isfile(fname) - return - - -def test_fmi(): - run_flow_model() - run_transport_model() - d = os.path.join(testdir, testgroup) - if os.path.isdir(d): - shutil.rmtree(d) - return - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - # run tests - test_fmi() +def test_fmi(function_tmpdir, targets): + mf6 = targets["mf6"] + run_flow_model(str(function_tmpdir), mf6) + run_transport_model(str(function_tmpdir), mf6) diff --git a/autotest/test_gwt_henry.py b/autotest/test_gwt_henry.py index 6b7eae4478c..19d3e93fd40 100644 --- a/autotest/test_gwt_henry.py +++ b/autotest/test_gwt_henry.py @@ -1,24 +1,12 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["henry01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -246,7 +234,7 @@ def chd_value(k): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") @@ -300,42 +288,18 @@ def eval_transport(sim): conc[-1, :, :], ) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_henry_nr.py b/autotest/test_gwt_henry_nr.py index b410def2e20..3c652cd7ae0 100644 --- a/autotest/test_gwt_henry_nr.py +++ b/autotest/test_gwt_henry_nr.py @@ -6,26 +6,14 @@ # the effects of tides on the aquifer. import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["henrynr01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # global model variables nlay = 20 @@ -388,8 +376,8 @@ def get_patch_collection(modelgrid, head, conc, cmap="jet", zorder=None): def make_plot(sim, headall, concall): print("making plots...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath sim = flopy.mf6.MFSimulation.load(sim_ws=ws) gwfname = "gwf_" + name gwtname = "gwt_" + name @@ -472,14 +460,12 @@ def make_plot(sim, headall, concall): fname = os.path.join(ws, fname) plt.savefig(fname, bbox_inches="tight") - return - def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath gwfname = "gwf_" + name gwtname = "gwt_" + name @@ -540,42 +526,19 @@ def eval_transport(sim): make_plot(sim, head, conc) assert False - return - -# - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_henry_openclose.py b/autotest/test_gwt_henry_openclose.py index 596d9e84708..86d8ff5b075 100644 --- a/autotest/test_gwt_henry_openclose.py +++ b/autotest/test_gwt_henry_openclose.py @@ -1,24 +1,12 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["henry_ext"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -249,7 +237,7 @@ def chd_value(k): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") @@ -303,42 +291,18 @@ def eval_transport(sim): conc[-1, :, :], ) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_ims_issue655.py b/autotest/test_gwt_ims_issue655.py index 07ef7b8bf6c..497c2585bad 100644 --- a/autotest/test_gwt_ims_issue655.py +++ b/autotest/test_gwt_ims_issue655.py @@ -8,27 +8,11 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["issue655a", "issue655b"] newton = [ @@ -38,9 +22,6 @@ laytyp = [1] ss = [1.0e-10] sy = [0.1] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) nlay, nrow, ncol = 1, 11, 11 @@ -310,39 +291,18 @@ def eval_transport(sim): # assert np.allclose(c, conc_calc, atol=0.001), msg # vold = v - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # run the test model - test.run_mf6(Simulation(exdir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build and run the test model - for idx, exdir in enumerate(exdirs): - test_mf6model(idx, exdir) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_ist01.py b/autotest/test_gwt_ist01.py index b9ea2a9ea4e..a87d6be5de0 100644 --- a/autotest/test_gwt_ist01.py +++ b/autotest/test_gwt_ist01.py @@ -6,27 +6,11 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["ist01"] laytyp = [1] @@ -34,10 +18,6 @@ sy = [0.1] thetaim = [0.05] zetaim = [0.1] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" nlay, nrow, ncol = 1, 1, 1 @@ -243,27 +223,19 @@ def build_model(idx, dir): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name gwfname = "gwf_" + name # head fpth = os.path.join(sim.simpath, f"{gwfname}.hds") - try: - hobj = flopy.utils.HeadFile(fpth, precision="double") - head = hobj.get_alldata().flatten() - except: - assert False, f'could not load data from "{fpth}"' + hobj = flopy.utils.HeadFile(fpth, precision="double") + head = hobj.get_alldata().flatten() # mobile concentration fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") - try: - cobj = flopy.utils.HeadFile( - fpth, precision="double", text="CONCENTRATION" - ) - conc = cobj.get_alldata().flatten() - except: - assert False, f'could not load data from "{fpth}"' + cobj = flopy.utils.HeadFile(fpth, precision="double", text="CONCENTRATION") + conc = cobj.get_alldata().flatten() # immobile concentration fpth = os.path.join(sim.simpath, f"{gwtname}.ist.ucn") @@ -287,49 +259,23 @@ def eval_transport(sim): rate_sim = immrate[i]["q"][0] saturation = 0.5 volume = 10.0 * 10.0 * 10.0 - rate_calc = ( - (cim[i] - conc[i]) * zetaim[sim.idxsim] * saturation * volume - ) + rate_calc = (cim[i] - conc[i]) * zetaim[0] * saturation * volume print(t, conc[i], cim[i], rate_sim, rate_calc) msg = f"Rate: {rate_sim} /= {rate_calc} for time {t}" assert np.allclose(rate_sim, rate_calc), msg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_lkt01.py b/autotest/test_gwt_lkt01.py index e3407bbafdb..4971e5c9412 100644 --- a/autotest/test_gwt_lkt01.py +++ b/autotest/test_gwt_lkt01.py @@ -4,26 +4,14 @@ # leaks into the aquifer. import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["lkt_01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -346,14 +334,14 @@ def build_model(idx, dir): def get_mfsim(testsim): - ws = exdirs[testsim.idxsim] + ws = testsim.simpath sim = flopy.mf6.MFSimulation.load(sim_ws=ws) return sim def eval_csv_information(testsim): sim = get_mfsim(testsim) - name = ex[testsim.idxsim] + name = testsim.name gwfname = "gwf_" + name gwtname = "gwt_" + name gwf = sim.get_model(gwfname) @@ -362,9 +350,9 @@ def eval_csv_information(testsim): lak_budget = gwf.lak.output.budgetcsv().data result = lak_budget["PERCENT_DIFFERENCE"] answer = np.zeros(result.shape) - assert np.allclose(result, answer), f"Lake package does not have zero mass balance error: {result}" - - return + assert np.allclose( + result, answer + ), f"Lake package does not have zero mass balance error: {result}" def eval_results(sim): @@ -374,7 +362,7 @@ def eval_results(sim): eval_csv_information(sim) # ensure lake concentrations were saved - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fname = gwtname + ".lkt.bin" fname = os.path.join(sim.simpath, fname) @@ -444,39 +432,18 @@ def eval_results(sim): # uncomment when testing # assert False - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_lkt02.py b/autotest/test_gwt_lkt02.py index 412ebc19ae9..15c29b6b9aa 100644 --- a/autotest/test_gwt_lkt02.py +++ b/autotest/test_gwt_lkt02.py @@ -2,26 +2,14 @@ # move solute from one lake to another. import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["lkt_02"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -368,7 +356,7 @@ def eval_results(sim): print("evaluating results...") # ensure lake concentrations were saved - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fname = gwtname + ".lkt.bin" fname = os.path.join(sim.simpath, fname) @@ -497,39 +485,18 @@ def eval_results(sim): # uncomment when testing # assert False - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_lkt03.py b/autotest/test_gwt_lkt03.py index d89912be6ec..efd98105085 100644 --- a/autotest/test_gwt_lkt03.py +++ b/autotest/test_gwt_lkt03.py @@ -2,26 +2,14 @@ # such as rainfall to make sure mixing is calculated correctly. import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["lkt_03"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -348,7 +336,7 @@ def eval_results(sim): print("evaluating results...") # ensure lake concentrations were saved - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fname = gwtname + ".lkt.bin" fname = os.path.join(sim.simpath, fname) @@ -393,39 +381,18 @@ def eval_results(sim): # uncomment when testing # assert False - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_lkt04.py b/autotest/test_gwt_lkt04.py index 7a906bb9000..f8bb2cf2c65 100644 --- a/autotest/test_gwt_lkt04.py +++ b/autotest/test_gwt_lkt04.py @@ -5,27 +5,17 @@ # should remain at zero. import os + +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["lkt_04"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -def build_model(idx, dir): +def build_model(idx, dir, exe): lx = 5.0 lz = 1.0 nlay = 1 @@ -59,9 +49,8 @@ def build_model(idx, dir): name = ex[idx] # build MODFLOW 6 files - ws = dir sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name="mf6", sim_ws=ws + sim_name=name, version="mf6", exe_name=exe, sim_ws=dir ) # create tdis package tdis = flopy.mf6.ModflowTdis( @@ -345,14 +334,14 @@ def build_model(idx, dir): def get_mfsim(testsim): - ws = exdirs[testsim.idxsim] + ws = testsim.simpath sim = flopy.mf6.MFSimulation.load(sim_ws=ws) return sim def eval_csv_information(testsim): sim = get_mfsim(testsim) - name = ex[testsim.idxsim] + name = testsim.name gwfname = "gwf_" + name gwtname = "gwt_" + name gwf = sim.get_model(gwfname) @@ -381,8 +370,6 @@ def eval_csv_information(testsim): assert success, f"One or more errors encountered in budget checks" - return - def eval_results(sim): print("evaluating results...") @@ -391,7 +378,7 @@ def eval_results(sim): eval_csv_information(sim) # ensure lake concentrations were saved - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fname = gwtname + ".lkt.bin" fname = os.path.join(sim.simpath, fname) @@ -485,39 +472,19 @@ def eval_results(sim): # uncomment when testing # assert False - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + mf6 = targets["mf6"] + test = TestFramework() + test.build(lambda i, w: build_model(i, w, mf6), idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_moc3d01.py b/autotest/test_gwt_moc3d01.py index 6aa18374340..f9a084e5160 100644 --- a/autotest/test_gwt_moc3d01.py +++ b/autotest/test_gwt_moc3d01.py @@ -1,27 +1,10 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = [ "moc3d01a", @@ -38,10 +21,6 @@ retardation = [None, None, None, None, 40.0, 4.0, 2.0, None] perlens = 4 * [120.0] + 3 * [240.0] + [120.0] decay = 7 * [None] + [0.01] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -371,44 +350,18 @@ def eval_transport(sim): tsres, tssim ), "simulated concentrations do not match with known solution." - return - - -# - No need to change any code below - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_moc3d01_zod.py b/autotest/test_gwt_moc3d01_zod.py index 30ad34d1b99..395298e0243 100644 --- a/autotest/test_gwt_moc3d01_zod.py +++ b/autotest/test_gwt_moc3d01_zod.py @@ -5,29 +5,12 @@ # where concentrations are zero. import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = [ "moc3d01zoda", @@ -38,10 +21,6 @@ retardation = [None, 40, None, 40] decay = [0.01, 0.01, 0.1, 0.1] ist_package = [False, False, True, True] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -441,11 +420,11 @@ def eval_transport(sim): makeplot = False if makeplot: fname = "fig-ct.pdf" - fname = os.path.join(exdirs[sim.idxsim], fname) + fname = os.path.join(ex[sim.idxsim], fname) make_plot_ct(tssim, fname) fname = "fig-cd.pdf" - fname = os.path.join(exdirs[sim.idxsim], fname) + fname = os.path.join(ex[sim.idxsim], fname) make_plot_cd(cobj, fname) tssim = tssim[::10] @@ -577,44 +556,18 @@ def eval_transport(sim): if tsres is not None: assert np.allclose(tsres, tssim), errmsg - return - - -# - No need to change any code below - @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_moc3d02.py b/autotest/test_gwt_moc3d02.py index 7b349b471aa..4d2b476c3dc 100644 --- a/autotest/test_gwt_moc3d02.py +++ b/autotest/test_gwt_moc3d02.py @@ -1,34 +1,13 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["moc3d02a", "moc3d02b"] xt3d = [None, True] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -329,42 +308,19 @@ def eval_transport(sim): cres, csim, rtol=1.0e-4 ), "simulated concentrations do not match with known solution." - return - -# - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_moc3d03.py b/autotest/test_gwt_moc3d03.py index 866c2d9df1e..f236107ad1d 100644 --- a/autotest/test_gwt_moc3d03.py +++ b/autotest/test_gwt_moc3d03.py @@ -1,33 +1,12 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["moc3d03"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -258,7 +237,7 @@ def build_model(idx, dir): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") @@ -311,42 +290,19 @@ def eval_transport(sim): cres, csim.diagonal().ravel() ), "simulated concentrations do not match with known solution." - return - -# - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_mst01.py b/autotest/test_gwt_mst01.py index e732c1c1ce7..d1f53e59118 100644 --- a/autotest/test_gwt_mst01.py +++ b/autotest/test_gwt_mst01.py @@ -1,36 +1,15 @@ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["mst01"] laytyp = [1] ss = [0.0] sy = [0.1] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" nlay, nrow, ncol = 4, 1, 1 @@ -240,17 +219,12 @@ def build_model(idx, dir): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") - try: - cobj = flopy.utils.HeadFile( - fpth, precision="double", text="CONCENTRATION" - ) - conc1 = cobj.get_data(totim=3.0) - except: - assert False, f'could not load data from "{fpth}"' + cobj = flopy.utils.HeadFile(fpth, precision="double", text="CONCENTRATION") + conc1 = cobj.get_data(totim=3.0) # end of stress period 1 cres1 = np.ones((nlay, nrow, ncol), float) @@ -258,42 +232,18 @@ def eval_transport(sim): "simulated concentrations do not match " "with known solution." ) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_mst02.py b/autotest/test_gwt_mst02.py index 410ec71309d..18a2a1e33b6 100644 --- a/autotest/test_gwt_mst02.py +++ b/autotest/test_gwt_mst02.py @@ -3,36 +3,15 @@ """ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["mst02a", "mst02b"] distcoef = [0.0, 1.0] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" nlay, nrow, ncol = 1, 1, 2 # time series answers for the two simulations @@ -277,42 +256,18 @@ def eval_transport(sim): except: assert False, f'could not load data from "{fpth}"' - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_mst03.py b/autotest/test_gwt_mst03.py index 7a4874e966c..036cfa4f296 100644 --- a/autotest/test_gwt_mst03.py +++ b/autotest/test_gwt_mst03.py @@ -7,36 +7,16 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["mst03"] laytyp = [1] ss = [1.0e-10] sy = [0.1] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" nlay, nrow, ncol = 1, 1, 1 @@ -238,25 +218,17 @@ def build_model(idx, dir): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name gwfname = "gwf_" + name fpth = os.path.join(sim.simpath, f"{gwfname}.hds") - try: - hobj = flopy.utils.HeadFile(fpth, precision="double") - head = hobj.get_alldata().flatten() - except: - assert False, f'could not load data from "{fpth}"' + hobj = flopy.utils.HeadFile(fpth, precision="double") + head = hobj.get_alldata().flatten() fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") - try: - cobj = flopy.utils.HeadFile( - fpth, precision="double", text="CONCENTRATION" - ) - conc = cobj.get_alldata().flatten() - except: - assert False, f'could not load data from "{fpth}"' + cobj = flopy.utils.HeadFile(fpth, precision="double", text="CONCENTRATION") + conc = cobj.get_alldata().flatten() # calculations times = hobj.get_times() @@ -312,42 +284,18 @@ def eval_transport(sim): errmsg = f"{conc}\n{canswer}" assert np.allclose(conc, canswer, atol=1.0e-8), errmsg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_mst04_noadv.py b/autotest/test_gwt_mst04_noadv.py index d4fc01c690e..14d711d7b16 100644 --- a/autotest/test_gwt_mst04_noadv.py +++ b/autotest/test_gwt_mst04_noadv.py @@ -6,35 +6,13 @@ """ import os +import flopy import numpy as np import pytest +from framework import TestFramework +from simulation import TestSimulation -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -ex = [ - "mst04_noadv", -] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" +ex = ["mst04_noadv"] def build_model(idx, dir): @@ -134,59 +112,30 @@ def build_model(idx, dir): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") - try: - cobj = flopy.utils.HeadFile( - fpth, precision="double", text="CONCENTRATION" - ) - conc = cobj.get_data() - except: - assert False, f'could not load data from "{fpth}"' + cobj = flopy.utils.HeadFile(fpth, precision="double", text="CONCENTRATION") + conc = cobj.get_data() # The answer 1 cres = np.array([10.0]) msg = f"simulated concentrations do not match with known solution. {conc} {cres}" assert np.allclose(cres, conc.flatten()), msg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_mst05.py b/autotest/test_gwt_mst05.py index 4999f5a3c89..c305d3ff3f7 100644 --- a/autotest/test_gwt_mst05.py +++ b/autotest/test_gwt_mst05.py @@ -5,22 +5,14 @@ """ import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from binary_file_writer import uniform_flow_field, write_budget, write_head -from framework import testing_framework -from simulation import Simulation +from flopy.utils.binaryfile import write_budget, write_head +from flopy.utils.gridutil import uniform_flow_field +from framework import TestFramework +from simulation import TestSimulation ex = ["mst05a", "mst05b"] isotherm = ["freundlich", "langmuir"] @@ -28,10 +20,6 @@ sp2 = [0.7, 0.003] xmax_plot = [1500, 500] ymax_plot = [0.5, 1.0] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -319,42 +307,18 @@ def eval_transport(sim): fname = os.path.join(sim.simpath, "results.png") plt.savefig(fname) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_mst06_noadv.py b/autotest/test_gwt_mst06_noadv.py index 26710b34e9d..95dcc8882e2 100644 --- a/autotest/test_gwt_mst06_noadv.py +++ b/autotest/test_gwt_mst06_noadv.py @@ -7,35 +7,13 @@ """ import os +import flopy import numpy as np import pytest +from framework import TestFramework +from simulation import TestSimulation -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -ex = [ - "mst06_noadv", -] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" +ex = ["mst06_noadv"] def build_model(idx, dir): @@ -144,17 +122,12 @@ def build_model(idx, dir): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") - try: - cobj = flopy.utils.HeadFile( - fpth, precision="double", text="CONCENTRATION" - ) - conc = cobj.get_ts((0, 0, 0)) - except: - assert False, f'could not load data from "{fpth}"' + cobj = flopy.utils.HeadFile(fpth, precision="double", text="CONCENTRATION") + conc = cobj.get_ts((0, 0, 0)) # The answer # print(conc[:, 1]) @@ -191,42 +164,18 @@ def eval_transport(sim): ) assert np.allclose(decay_rate, decay_rate_answer), msg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_mt3dms_p01.py b/autotest/test_gwt_mt3dms_p01.py index 43e8da72055..1a7d0998c9b 100644 --- a/autotest/test_gwt_mt3dms_p01.py +++ b/autotest/test_gwt_mt3dms_p01.py @@ -20,36 +20,11 @@ """ import os -import shutil -import sys +import flopy import numpy as np -import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -import targets - -exe_name_mf = targets.target_dict["mf2005s"] -exe_name_mt = targets.target_dict["mt3dms"] -exe_name_mf6 = targets.target_dict["mf6"] -testdir = "./temp" + testgroup = "mt3dms_p01" -remove_files = True def p01mt3d( @@ -62,6 +37,8 @@ def p01mt3d( prsity2=None, rc2=None, zero_order_decay=False, + mf2005s="mf2005s", + mt3dms="mt3dms", ): nlay = 1 nrow = 1 @@ -85,7 +62,7 @@ def p01mt3d( modelname_mf = "p01_mf" mf = flopy.modflow.Modflow( - modelname=modelname_mf, model_ws=model_ws, exe_name=exe_name_mf + modelname=modelname_mf, model_ws=model_ws, exe_name=mf2005s ) dis = flopy.modflow.ModflowDis( mf, @@ -115,7 +92,7 @@ def p01mt3d( mt = flopy.mt3d.Mt3dms( modelname=modelname_mt, model_ws=model_ws, - exe_name=exe_name_mt, + exe_name=mt3dms, modflowmodel=mf, ) c0 = 1.0 @@ -209,6 +186,7 @@ def p01mf6( prsity2=None, onelambda=False, zero_order_decay=False, + exe="mf6", ): name = "p01" nlay, nrow, ncol = 1, 1, 101 @@ -242,9 +220,8 @@ def p01mf6( tdis_rc.append((perlen[i], nstp[i], tsmult[i])) ws = model_ws - exe_name = os.path.abspath(exe_name_mf6) sim = flopy.mf6.MFSimulation( - sim_name=name, version="mf6", exe_name=exe_name, sim_ws=ws + sim_name=name, version="mf6", exe_name=exe, sim_ws=ws ) from flopy.mf6.mfbase import VerbosityLevel @@ -481,8 +458,7 @@ def p01mf6( return sim, conc -def test_mt3dmsp01a(): - +def test_mt3dmsp01a(function_tmpdir, targets): longitudinal_dispersivity = 0.0 retardation = 1.0 decay_rate = 0.00 @@ -490,7 +466,8 @@ def test_mt3dmsp01a(): zeta = None prsity2 = None - mf6_ws = os.path.join(testdir, testgroup + "a") + mf6 = targets["mf6"] + mf6_ws = str(function_tmpdir / (testgroup + "a")) sim, conc_mf6 = p01mf6( mf6_ws, longitudinal_dispersivity, @@ -499,8 +476,11 @@ def test_mt3dmsp01a(): mixelm, zeta, prsity2, + exe=mf6, ) + mf2005 = targets["mf2005s"] + mt3dms = targets["mt3dms"] mt3d_ws = os.path.join(mf6_ws, "mt3d") mf, mt, conc_mt3d, cvt, mvt = p01mt3d( mt3d_ws, @@ -510,6 +490,8 @@ def test_mt3dmsp01a(): mixelm, zeta, prsity2, + mf2005s=mf2005, + mt3dms=mt3dms, ) msg = f"concentrations not equal {conc_mt3d} {conc_mf6}" @@ -540,13 +522,8 @@ def test_mt3dmsp01a(): bobj.file.close() assert np.allclose(0.0, storage_sorbed), f"{storage_sorbed}" - if remove_files: - shutil.rmtree(mf6_ws) - return - - -def test_mt3dmsp01b(): +def test_mt3dmsp01b(function_tmpdir, targets): longitudinal_dispersivity = 10.0 retardation = 1.0 decay_rate = 0.00 @@ -554,7 +531,8 @@ def test_mt3dmsp01b(): zeta = None prsity2 = None - mf6_ws = os.path.join(testdir, testgroup + "b") + mf6 = targets["mf6"] + mf6_ws = str(function_tmpdir / (testgroup + "b")) sim, conc_mf6 = p01mf6( mf6_ws, longitudinal_dispersivity, @@ -563,8 +541,11 @@ def test_mt3dmsp01b(): mixelm, zeta, prsity2, + exe=mf6, ) + mf2005 = targets["mf2005s"] + mt3dms = targets["mt3dms"] mt3d_ws = os.path.join(mf6_ws, "mt3d") mf, mt, conc_mt3d, cvt, mvt = p01mt3d( mt3d_ws, @@ -574,17 +555,15 @@ def test_mt3dmsp01b(): mixelm, zeta, prsity2, + mf2005s=mf2005, + mt3dms=mt3dms, ) msg = f"concentrations not equal {conc_mt3d} {conc_mf6}" assert np.allclose(conc_mt3d, conc_mf6, atol=1e-4), msg - if remove_files: - shutil.rmtree(mf6_ws) - return - -def test_mt3dmsp01c(): +def test_mt3dmsp01c(function_tmpdir, targets): longitudinal_dispersivity = 10.0 retardation = 1.5 decay_rate = 0.00 @@ -592,7 +571,8 @@ def test_mt3dmsp01c(): zeta = None prsity2 = None - mf6_ws = os.path.join(testdir, testgroup + "c") + mf6 = targets["mf6"] + mf6_ws = str(function_tmpdir / (testgroup + "c")) sim, conc_mf6 = p01mf6( mf6_ws, longitudinal_dispersivity, @@ -601,8 +581,11 @@ def test_mt3dmsp01c(): mixelm, zeta, prsity2, + exe=mf6, ) + mf2005 = targets["mf2005s"] + mt3dms = targets["mt3dms"] mt3d_ws = os.path.join(mf6_ws, "mt3d") mf, mt, conc_mt3d, cvt, mvt = p01mt3d( mt3d_ws, @@ -612,17 +595,15 @@ def test_mt3dmsp01c(): mixelm, zeta, prsity2, + mf2005s=mf2005, + mt3dms=mt3dms, ) msg = f"concentrations not equal {conc_mt3d} {conc_mf6}" assert np.allclose(conc_mt3d, conc_mf6, atol=1e-4), msg - if remove_files: - shutil.rmtree(mf6_ws) - return -def test_mt3dmsp01d(): - +def test_mt3dmsp01d(function_tmpdir, targets): longitudinal_dispersivity = 10.0 retardation = 1.5 decay_rate = 0.002 @@ -630,7 +611,8 @@ def test_mt3dmsp01d(): zeta = None prsity2 = None - mf6_ws = os.path.join(testdir, testgroup + "d") + mf6 = targets["mf6"] + mf6_ws = str(function_tmpdir / (testgroup + "d")) sim, conc_mf6 = p01mf6( mf6_ws, longitudinal_dispersivity, @@ -639,8 +621,11 @@ def test_mt3dmsp01d(): mixelm, zeta, prsity2, + exe=mf6, ) + mf2005 = targets["mf2005s"] + mt3dms = targets["mt3dms"] mt3d_ws = os.path.join(mf6_ws, "mt3d") mf, mt, conc_mt3d, cvt, mvt = p01mt3d( mt3d_ws, @@ -650,17 +635,15 @@ def test_mt3dmsp01d(): mixelm, zeta, prsity2, + mf2005s=mf2005, + mt3dms=mt3dms, ) msg = f"concentrations not equal {conc_mt3d} {conc_mf6}" assert np.allclose(conc_mt3d, conc_mf6, atol=1e-4), msg - if remove_files: - shutil.rmtree(mf6_ws) - return - -def test_mt3dmsp01e(): +def test_mt3dmsp01e(function_tmpdir, targets): longitudinal_dispersivity = 10.0 retardation = 1.5 decay_rate = 0.002 @@ -668,7 +651,8 @@ def test_mt3dmsp01e(): zeta = 0.1 prsity2 = 0.05 - mf6_ws = os.path.join(testdir, testgroup + "e") + mf6 = targets["mf6"] + mf6_ws = str(function_tmpdir / (testgroup + "e")) sim, conc_mf6 = p01mf6( mf6_ws, longitudinal_dispersivity, @@ -677,8 +661,11 @@ def test_mt3dmsp01e(): mixelm, zeta, prsity2, + exe=mf6, ) + mf2005 = targets["mf2005s"] + mt3dms = targets["mt3dms"] mt3d_ws = os.path.join(mf6_ws, "mt3d") mf, mt, conc_mt3d, cvt, mvt = p01mt3d( mt3d_ws, @@ -688,17 +675,15 @@ def test_mt3dmsp01e(): mixelm, zeta, prsity2, + mf2005s=mf2005, + mt3dms=mt3dms, ) msg = f"concentrations not equal {conc_mt3d} {conc_mf6}" assert np.allclose(conc_mt3d, conc_mf6, atol=1e-1), msg - if remove_files: - shutil.rmtree(mf6_ws) - return -def test_mt3dmsp01f(): - +def test_mt3dmsp01f(function_tmpdir, targets): longitudinal_dispersivity = 10.0 retardation = 1.5 decay_rate = 0.002 @@ -706,7 +691,8 @@ def test_mt3dmsp01f(): zeta = 0.1 prsity2 = 0.05 - mf6_ws = os.path.join(testdir, testgroup + "f") + mf6 = targets["mf6"] + mf6_ws = str(function_tmpdir / (testgroup + "f")) sim, conc_mf6 = p01mf6( mf6_ws, longitudinal_dispersivity, @@ -716,8 +702,11 @@ def test_mt3dmsp01f(): zeta, prsity2, onelambda=True, + exe=mf6, ) + mf2005 = targets["mf2005s"] + mt3dms = targets["mt3dms"] mt3d_ws = os.path.join(mf6_ws, "mt3d") mf, mt, conc_mt3d, cvt, mvt = p01mt3d( mt3d_ws, @@ -727,17 +716,15 @@ def test_mt3dmsp01f(): mixelm, zeta, prsity2, + mf2005s=mf2005, + mt3dms=mt3dms, ) msg = f"concentrations not equal {conc_mt3d} {conc_mf6}" assert np.allclose(conc_mt3d, conc_mf6, atol=1e-1), msg - if remove_files: - shutil.rmtree(mf6_ws) - return - -def test_mt3dmsp01g(): +def test_mt3dmsp01g(function_tmpdir, targets): longitudinal_dispersivity = 0.0 retardation = 1.0 decay_rate = -1.0 @@ -745,7 +732,8 @@ def test_mt3dmsp01g(): zeta = None prsity2 = None - mf6_ws = os.path.join(testdir, testgroup + "g") + mf6 = targets["mf6"] + mf6_ws = str(function_tmpdir / (testgroup + "g")) sim, conc_mf6 = p01mf6( mf6_ws, longitudinal_dispersivity, @@ -755,8 +743,11 @@ def test_mt3dmsp01g(): zeta, prsity2, zero_order_decay=True, + exe=mf6, ) + mf2005 = targets["mf2005s"] + mt3dms = targets["mt3dms"] mt3d_ws = os.path.join(mf6_ws, "mt3d") mf, mt, conc_mt3d, cvt, mvt = p01mt3d( mt3d_ws, @@ -768,22 +759,9 @@ def test_mt3dmsp01g(): prsity2, rc2=0.0, zero_order_decay=True, + mf2005s=mf2005, + mt3dms=mt3dms, ) msg = f"concentrations not equal {conc_mt3d} {conc_mf6}" assert np.allclose(conc_mt3d, conc_mf6, atol=1.0e-4), msg - if remove_files: - shutil.rmtree(mf6_ws) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - test_mt3dmsp01a() - test_mt3dmsp01b() - test_mt3dmsp01c() - test_mt3dmsp01d() - test_mt3dmsp01e() - test_mt3dmsp01f() - test_mt3dmsp01g() diff --git a/autotest/test_gwt_mvt01.py b/autotest/test_gwt_mvt01.py index eb69289bf9e..1818b8f5724 100644 --- a/autotest/test_gwt_mvt01.py +++ b/autotest/test_gwt_mvt01.py @@ -5,26 +5,14 @@ # There is no flow between the stream and the aquifer. import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["mvt_01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -497,7 +485,7 @@ def eval_results(sim): print("evaluating results...") # ensure lake concentrations were saved - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fname = gwtname + ".sft.bin" fname = os.path.join(sim.simpath, fname) @@ -558,39 +546,18 @@ def eval_results(sim): # uncomment when testing so files aren't deleted # assert False - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_mvt02.py b/autotest/test_gwt_mvt02.py index 573f4a098c2..20dfa5e4762 100644 --- a/autotest/test_gwt_mvt02.py +++ b/autotest/test_gwt_mvt02.py @@ -5,26 +5,14 @@ # There is no flow between the stream and the aquifer. import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["mvt_02"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -398,7 +386,7 @@ def build_model(idx, dir): def eval_results(sim): print("evaluating results...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name # Load csv budget and make sure names are correct @@ -489,39 +477,18 @@ def eval_results(sim): # uncomment when testing so files aren't deleted # assert False - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_mvt02fmi.py b/autotest/test_gwt_mvt02fmi.py index 3147d066fa6..702b9a80697 100644 --- a/autotest/test_gwt_mvt02fmi.py +++ b/autotest/test_gwt_mvt02fmi.py @@ -5,35 +5,13 @@ # There is no flow between the stream and the aquifer. import os -import shutil +from os.path import join +import flopy import numpy as np -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -import targets -from framework import set_teardown_test - -exe_name_mf6 = targets.target_dict["mf6"] -exe_name_mf6 = os.path.abspath(exe_name_mf6) - -testdir = "./temp" testgroup = "mvt02fmi" -d = os.path.join(testdir, testgroup) -if os.path.isdir(d): - shutil.rmtree(d) - - ex = ["mvt02fmi"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # parameters lx = 7.0 @@ -61,14 +39,11 @@ hclose, rclose, relax = 1e-8, 1e-6, 0.97 -def run_flow_model(): - +def run_flow_model(dir, exe): name = "flow" gwfname = name - wsf = os.path.join(testdir, testgroup, name) - sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=wsf, exe_name=exe_name_mf6 - ) + wsf = join(dir, testgroup, name) + sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=wsf, exe_name=exe) # create tdis package tdis = flopy.mf6.ModflowTdis( @@ -262,18 +237,15 @@ def run_flow_model(): errmsg = f"flow model did not terminate successfully\n{buff}" assert success, errmsg - return - - -def run_transport_model(): +def run_transport_model(dir, exe): name = "transport" gwtname = name - wst = os.path.join(testdir, testgroup, name) + wst = join(dir, testgroup, name) sim = flopy.mf6.MFSimulation( sim_name=name, version="mf6", - exe_name=exe_name_mf6, + exe_name=exe, sim_ws=wst, continue_=False, memory_print_option=["ALL"], @@ -496,24 +468,8 @@ def run_transport_model(): # uncomment when testing so files aren't deleted # assert False - return - - -def test_mvt02fmi(): - run_flow_model() - run_transport_model() - d = os.path.join(testdir, testgroup) - - teardowntest = set_teardown_test() - if teardowntest: - if os.path.isdir(d): - shutil.rmtree(d) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - # run tests - test_mvt02fmi() +def test_mvt02fmi(function_tmpdir, targets): + mf6 = targets.mf6 + run_flow_model(str(function_tmpdir), mf6) + run_transport_model(str(function_tmpdir), mf6) diff --git a/autotest/test_gwt_mwt01.py b/autotest/test_gwt_mwt01.py index 971aa819f63..bf70531e86f 100644 --- a/autotest/test_gwt_mwt01.py +++ b/autotest/test_gwt_mwt01.py @@ -4,26 +4,14 @@ # flows into the aquifer. import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["mwt_01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -320,8 +308,8 @@ def build_model(idx, dir): def check_obs(sim): print("checking obs...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath sim = flopy.mf6.MFSimulation.load(sim_ws=ws) gwfname = "gwf_" + name gwtname = "gwt_" + name @@ -385,14 +373,13 @@ def check_obs(sim): ) assert success, "One or more MWT obs checks did not pass" - return def eval_results(sim): print("evaluating results...") # ensure mwt concentrations were saved - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fname = gwtname + ".mwt.bin" fname = os.path.join(sim.simpath, fname) @@ -405,39 +392,18 @@ def eval_results(sim): check_obs(sim) - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_mwt02.py b/autotest/test_gwt_mwt02.py index f91f2a92c6f..37129a329a1 100644 --- a/autotest/test_gwt_mwt02.py +++ b/autotest/test_gwt_mwt02.py @@ -2,26 +2,14 @@ # information. import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["mwt_02"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -406,8 +394,8 @@ def build_model(idx, dir): def make_plot(sim): print("making plots...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath sim = flopy.mf6.MFSimulation.load(sim_ws=ws) gwfname = "gwf_" + name gwtname = "gwt_" + name @@ -489,39 +477,14 @@ def eval_results(sim): # uncomment when testing # assert False - return - - -# - No need to change any code below -@pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), -) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +@pytest.mark.slow +@pytest.mark.parametrize("name", ex) +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation(name, exe_dict=targets, exfunc=eval_results, idxsim=0), + ws, + ) diff --git a/autotest/test_gwt_obs01.py b/autotest/test_gwt_obs01.py index 6dab2574d55..97416f1d721 100644 --- a/autotest/test_gwt_obs01.py +++ b/autotest/test_gwt_obs01.py @@ -6,28 +6,16 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = [ "gwt_obs01a", ] scheme = ["upstream"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -257,25 +245,17 @@ def build_model(idx, dir): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name # MODFLOW 6 output control concentrations fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") - try: - cobj = flopy.utils.HeadFile( - fpth, precision="double", text="CONCENTRATION" - ) - conc = cobj.get_alldata() - except: - assert False, f'could not load data from "{fpth}"' + cobj = flopy.utils.HeadFile(fpth, precision="double", text="CONCENTRATION") + conc = cobj.get_alldata() # MODFLOW 6 observation package concentrations fpth = os.path.join(sim.simpath, "conc_obs.csv") - try: - tc = np.genfromtxt(fpth, names=True, delimiter=",") - except: - assert False, f'could not load data from "{fpth}"' + tc = np.genfromtxt(fpth, names=True, delimiter=",") assert np.allclose( tc["1_1_10"], conc[:, 0, 0, 9] @@ -285,42 +265,18 @@ def eval_transport(sim): tc["1_1_50"], conc[:, 0, 0, 49] ), "obs concentrations do not match oc concentrations." - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_prudic2004t2.py b/autotest/test_gwt_prudic2004t2.py index 2d1f2d411ee..6c052338a59 100644 --- a/autotest/test_gwt_prudic2004t2.py +++ b/autotest/test_gwt_prudic2004t2.py @@ -7,27 +7,17 @@ import os import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from conftest import project_root_path +from framework import TestFramework +from simulation import TestSimulation ex = ["prudic2004t2"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - -data_ws = "./data/prudic2004test2/" -fname = os.path.join(data_ws, "lakibd.dat") +data_path = project_root_path / "autotest" / "data" +model_path = data_path / "prudic2004test2" +fname = str(model_path / "lakibd.dat") lakibd = np.loadtxt(fname, dtype=int) @@ -84,10 +74,10 @@ def build_model(idx, dir): delr = 405.665 delc = 403.717 top = 100.0 - fname = os.path.join(data_ws, "bot1.dat") + fname = str(model_path / "bot1.dat") bot0 = np.loadtxt(fname) botm = [bot0] + [bot0 - (15.0 * k) for k in range(1, nlay)] - fname = os.path.join(data_ws, "idomain1.dat") + fname = str(model_path / "idomain1.dat") idomain0 = np.loadtxt(fname, dtype=int) idomain = nlay * [idomain0] dis = flopy.mf6.ModflowGwfdis( @@ -100,7 +90,6 @@ def build_model(idx, dir): top=top, botm=botm, idomain=idomain, - length_units="feet", ) idomain = dis.idomain.array @@ -146,7 +135,7 @@ def build_model(idx, dir): ) chdlist = [] - fname = os.path.join(data_ws, "chd.dat") + fname = str(model_path / "chd.dat") for line in open(fname, "r").readlines(): ll = line.strip().split() if len(ll) == 4: @@ -166,7 +155,7 @@ def build_model(idx, dir): ) rivlist = [] - fname = os.path.join(data_ws, "riv.dat") + fname = str(model_path / "riv.dat") for line in open(fname, "r").readlines(): ll = line.strip().split() if len(ll) == 7: @@ -189,7 +178,7 @@ def build_model(idx, dir): )[0] for i, t in enumerate(rivlist): rivra[i] = tuple(t) - sfrpd = np.genfromtxt(data_ws + "sfr-packagedata.dat", names=True) + sfrpd = np.genfromtxt(model_path / "sfr-packagedata.dat", names=True) sfrpackagedata = flopy.mf6.ModflowGwfsfr.packagedata.empty( gwf, boundnames=True, maxbound=sfrpd.shape[0] ) @@ -200,7 +189,7 @@ def build_model(idx, dir): if name in sfrpd.dtype.names: sfrpackagedata[name] = sfrpd[name] sfrpackagedata["boundname"] = rivra["boundname"] - with open(data_ws + "sfr-connectiondata.dat") as f: + with open(model_path / "sfr-connectiondata.dat") as f: lines = f.readlines() sfrconnectiondata = [] for line in lines: @@ -327,16 +316,13 @@ def build_model(idx, dir): [1, 35.2, nlakecon[1], "lake2"], ] # - outlets = [ - [0, 0, -1, "MANNING", 44.5, 3.36493214532915, 0.03, 0.2187500e-02] - ] + outlets = [[0, 0, -1, "MANNING", 44.5, 5.000000, 0.03, 0.2187500e-02]] lake_on = True if lake_on: lak = flopy.mf6.ModflowGwflak( gwf, time_conversion=86400.000, - length_conversion=3.28081, print_stage=True, print_flows=True, stage_filerecord=gwfname + ".lak.bin", @@ -599,8 +585,8 @@ def build_model(idx, dir): def make_concentration_vs_time(sim): print("making plot of concentration versus time...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath sim = flopy.mf6.MFSimulation.load(sim_ws=ws) gwfname = "gwf_" + name gwtname = "gwt_" + name @@ -658,8 +644,8 @@ def make_concentration_map(sim): 500, ] - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath simfp = flopy.mf6.MFSimulation.load(sim_ws=ws) gwfname = "gwf_" + name gwtname = "gwt_" + name @@ -697,8 +683,8 @@ def make_concentration_map(sim): def check_obs(sim): print("checking obs...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath sim = flopy.mf6.MFSimulation.load(sim_ws=ws) gwfname = "gwf_" + name gwtname = "gwt_" + name @@ -843,8 +829,8 @@ def eval_results(sim): make_concentration_map(sim) # ensure concentrations were saved - ws = exdirs[sim.idxsim] - name = ex[sim.idxsim] + ws = sim.simpath + name = sim.name gwtname = "gwt_" + name check_obs(sim) @@ -984,39 +970,19 @@ def eval_results(sim): # uncomment when testing # assert False - return - -# - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_prudic2004t2fmi.py b/autotest/test_gwt_prudic2004t2fmi.py index 00551a1d3a6..94378e064d0 100644 --- a/autotest/test_gwt_prudic2004t2fmi.py +++ b/autotest/test_gwt_prudic2004t2fmi.py @@ -1,40 +1,16 @@ # tests to ability to run flow model first followed by transport model import os -import shutil +from os.path import join +import flopy import numpy as np import pytest +from conftest import project_root_path -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - - -import targets -from framework import set_teardown_test - -exe_name_mf6 = targets.target_dict["mf6"] -exe_name_mf6 = os.path.abspath(exe_name_mf6) - -data_ws = os.path.abspath("./data/prudic2004test2/") -testdir = "./temp" +data_path = project_root_path / "autotest" / "data" +model_path = str(data_path / "prudic2004test2") testgroup = "prudic2004t2fmi" -d = os.path.join(testdir, testgroup) -if os.path.isdir(d): - shutil.rmtree(d) nlay = 8 nrow = 36 @@ -42,22 +18,20 @@ delr = 405.665 delc = 403.717 top = 100.0 -fname = os.path.join(data_ws, "bot1.dat") +fname = os.path.join(model_path, "bot1.dat") bot0 = np.loadtxt(fname) botm = [bot0] + [bot0 - (15.0 * k) for k in range(1, nlay)] -fname = os.path.join(data_ws, "idomain1.dat") +fname = os.path.join(model_path, "idomain1.dat") idomain0 = np.loadtxt(fname, dtype=int) idomain = nlay * [idomain0] -def run_flow_model(): +def run_flow_model(dir, exe): global idomain name = "flow" gwfname = name - wsf = os.path.join(testdir, testgroup, name) - sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=wsf, exe_name=exe_name_mf6 - ) + wsf = join(dir, testgroup, name) + sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=wsf, exe_name=exe) tdis_rc = [(1.0, 1, 1.0), (365.25 * 25, 1, 1.0)] nper = len(tdis_rc) tdis = flopy.mf6.ModflowTdis( @@ -144,7 +118,7 @@ def run_flow_model(): ) chdlist = [] - fname = os.path.join(data_ws, "chd.dat") + fname = os.path.join(model_path, "chd.dat") for line in open(fname, "r").readlines(): ll = line.strip().split() if len(ll) == 4: @@ -164,7 +138,7 @@ def run_flow_model(): ) rivlist = [] - fname = os.path.join(data_ws, "riv.dat") + fname = os.path.join(model_path, "riv.dat") for line in open(fname, "r").readlines(): ll = line.strip().split() if len(ll) == 7: @@ -187,7 +161,7 @@ def run_flow_model(): )[0] for i, t in enumerate(rivlist): rivra[i] = tuple(t) - fname = os.path.join(data_ws, "sfr-packagedata.dat") + fname = os.path.join(model_path, "sfr-packagedata.dat") sfrpd = np.genfromtxt(fname, names=True) sfrpackagedata = flopy.mf6.ModflowGwfsfr.packagedata.empty( gwf, boundnames=True, maxbound=sfrpd.shape[0] @@ -199,7 +173,7 @@ def run_flow_model(): if name in sfrpd.dtype.names: sfrpackagedata[name] = sfrpd[name] sfrpackagedata["boundname"] = rivra["boundname"] - fname = os.path.join(data_ws, "sfr-connectiondata.dat") + fname = os.path.join(model_path, "sfr-connectiondata.dat") with open(fname) as f: lines = f.readlines() sfrconnectiondata = [] @@ -243,7 +217,7 @@ def run_flow_model(): observations=sfr_obs, ) - fname = os.path.join(data_ws, "lakibd.dat") + fname = os.path.join(model_path, "lakibd.dat") lakibd = np.loadtxt(fname, dtype=int) lakeconnectiondata = [] nlakecon = [0, 0] @@ -354,16 +328,13 @@ def run_flow_model(): [1, 35.2, nlakecon[1], "lake2"], ] # - outlets = [ - [0, 0, -1, "MANNING", 44.5, 3.36493214532915, 0.03, 0.2187500e-02] - ] + outlets = [[0, 0, -1, "MANNING", 44.5, 5.000000, 0.03, 0.2187500e-02]] lake_on = True if lake_on: lak = flopy.mf6.ModflowGwflak( gwf, time_conversion=86400.000, - length_conversion=3.28081, print_stage=True, print_flows=True, stage_filerecord=gwfname + ".lak.bin", @@ -458,17 +429,15 @@ def run_flow_model(): for node, node2, q in d: print(p1, node, p2, node2, q) - return - -def run_transport_model(): +def run_transport_model(dir, exe): name = "transport" gwtname = name - wst = os.path.join(testdir, testgroup, name) + wst = join(dir, testgroup, name) sim = flopy.mf6.MFSimulation( sim_name=name, version="mf6", - exe_name=exe_name_mf6, + exe_name=exe, sim_ws=wst, continue_=False, ) @@ -515,7 +484,6 @@ def run_transport_model(): top=top, botm=botm, idomain=idomain, - length_units="feet", ) ic = flopy.mf6.ModflowGwtic(gwt, strt=0.0) sto = flopy.mf6.ModflowGwtmst(gwt, porosity=0.3) @@ -811,23 +779,10 @@ def run_transport_model(): for rate1, rate2 in zip(csvra[name1], lstra[name2]): print(rate1, rate2) assert success_all, f"Comparisons failed for {failed_list}" - return - - -def test_prudic2004t2fmi(): - run_flow_model() - run_transport_model() - d = os.path.join(testdir, testgroup) - teardowntest = set_teardown_test() - if teardowntest: - if os.path.isdir(d): - shutil.rmtree(d) - return - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - # run tests - test_prudic2004t2fmi() +@pytest.mark.slow +def test_prudic2004t2fmi(function_tmpdir, targets): + mf6 = targets.mf6 + run_flow_model(str(function_tmpdir), mf6) + run_transport_model(str(function_tmpdir), mf6) diff --git a/autotest/test_gwt_prudic2004t2fmiats.py b/autotest/test_gwt_prudic2004t2fmiats.py index 68b1651eec9..446aec445e8 100644 --- a/autotest/test_gwt_prudic2004t2fmiats.py +++ b/autotest/test_gwt_prudic2004t2fmiats.py @@ -5,40 +5,16 @@ # failure occurs. import os -import shutil +from os.path import join +import flopy import numpy as np import pytest +from conftest import project_root_path -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - - -import targets -from framework import set_teardown_test - -exe_name_mf6 = targets.target_dict["mf6"] -exe_name_mf6 = os.path.abspath(exe_name_mf6) - -data_ws = os.path.abspath("./data/prudic2004test2/") -testdir = "./temp" +data_path = project_root_path / "autotest" / "data" +model_path = str(data_path / "prudic2004test2") testgroup = "prudic2004t2fmiats" -d = os.path.join(testdir, testgroup) -if os.path.isdir(d): - shutil.rmtree(d) nlay = 8 nrow = 36 @@ -46,22 +22,20 @@ delr = 405.665 delc = 403.717 top = 100.0 -fname = os.path.join(data_ws, "bot1.dat") +fname = os.path.join(model_path, "bot1.dat") bot0 = np.loadtxt(fname) botm = [bot0] + [bot0 - (15.0 * k) for k in range(1, nlay)] -fname = os.path.join(data_ws, "idomain1.dat") +fname = os.path.join(model_path, "idomain1.dat") idomain0 = np.loadtxt(fname, dtype=int) idomain = nlay * [idomain0] -def run_flow_model(): +def run_flow_model(dir, exe): global idomain name = "flow" gwfname = name - wsf = os.path.join(testdir, testgroup, name) - sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=wsf, exe_name=exe_name_mf6 - ) + wsf = join(dir, testgroup, name) + sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=wsf, exe_name=exe) tdis_rc = [(1.0, 1, 1.0), (365.25 * 25, 1, 1.0)] nper = len(tdis_rc) tdis = flopy.mf6.ModflowTdis( @@ -102,7 +76,6 @@ def run_flow_model(): top=top, botm=botm, idomain=idomain, - length_units="feet", ) idomain = dis.idomain.array @@ -149,7 +122,7 @@ def run_flow_model(): ) chdlist = [] - fname = os.path.join(data_ws, "chd.dat") + fname = os.path.join(model_path, "chd.dat") for line in open(fname, "r").readlines(): ll = line.strip().split() if len(ll) == 4: @@ -169,7 +142,7 @@ def run_flow_model(): ) rivlist = [] - fname = os.path.join(data_ws, "riv.dat") + fname = os.path.join(model_path, "riv.dat") for line in open(fname, "r").readlines(): ll = line.strip().split() if len(ll) == 7: @@ -192,7 +165,7 @@ def run_flow_model(): )[0] for i, t in enumerate(rivlist): rivra[i] = tuple(t) - fname = os.path.join(data_ws, "sfr-packagedata.dat") + fname = os.path.join(model_path, "sfr-packagedata.dat") sfrpd = np.genfromtxt(fname, names=True) sfrpackagedata = flopy.mf6.ModflowGwfsfr.packagedata.empty( gwf, boundnames=True, maxbound=sfrpd.shape[0] @@ -204,7 +177,7 @@ def run_flow_model(): if name in sfrpd.dtype.names: sfrpackagedata[name] = sfrpd[name] sfrpackagedata["boundname"] = rivra["boundname"] - fname = os.path.join(data_ws, "sfr-connectiondata.dat") + fname = os.path.join(model_path, "sfr-connectiondata.dat") with open(fname) as f: lines = f.readlines() sfrconnectiondata = [] @@ -248,7 +221,7 @@ def run_flow_model(): observations=sfr_obs, ) - fname = os.path.join(data_ws, "lakibd.dat") + fname = os.path.join(model_path, "lakibd.dat") lakibd = np.loadtxt(fname, dtype=int) lakeconnectiondata = [] nlakecon = [0, 0] @@ -359,16 +332,13 @@ def run_flow_model(): [1, 35.2, nlakecon[1], "lake2"], ] # - outlets = [ - [0, 0, -1, "MANNING", 44.5, 3.36493214532915, 0.03, 0.2187500e-02] - ] + outlets = [[0, 0, -1, "MANNING", 44.5, 5.000000, 0.03, 0.2187500e-02]] lake_on = True if lake_on: lak = flopy.mf6.ModflowGwflak( gwf, time_conversion=86400.000, - length_conversion=3.28081, print_stage=True, print_flows=True, stage_filerecord=gwfname + ".lak.bin", @@ -454,17 +424,15 @@ def run_flow_model(): for node, node2, q in d: print(p1, node, p2, node2, q) - return - -def run_transport_model(): +def run_transport_model(dir, exe): name = "transport" gwtname = name - wst = os.path.join(testdir, testgroup, name) + wst = join(dir, testgroup, name) sim = flopy.mf6.MFSimulation( sim_name=name, version="mf6", - exe_name=exe_name_mf6, + exe_name=exe, sim_ws=wst, continue_=False, ) @@ -879,23 +847,9 @@ def run_transport_model(): all_found ), "One or more required text strings not found in mfsim.lst" - return - - -def test_prudic2004t2fmiats(): - run_flow_model() - run_transport_model() - d = os.path.join(testdir, testgroup) - teardowntest = set_teardown_test() - if teardowntest: - if os.path.isdir(d): - shutil.rmtree(d) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - # run tests - test_prudic2004t2fmiats() +@pytest.mark.slow +def test_prudic2004t2fmiats(function_tmpdir, targets): + mf6 = targets.mf6 + run_flow_model(dir=str(function_tmpdir), exe=mf6) + run_transport_model(dir=str(function_tmpdir), exe=mf6) diff --git a/autotest/test_gwt_prudic2004t2gwtgwt.py b/autotest/test_gwt_prudic2004t2gwtgwt.py index 022a9ddc17d..71577f18af4 100644 --- a/autotest/test_gwt_prudic2004t2gwtgwt.py +++ b/autotest/test_gwt_prudic2004t2gwtgwt.py @@ -7,26 +7,16 @@ import os import sys +import flopy import numpy as np import pytest +from conftest import project_root_path +from framework import TestFramework +from simulation import TestSimulation -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation - -data_ws = "./data/prudic2004test2gwtgwt/" +data_path = project_root_path / "autotest" / "data" +model_path = str(data_path / "prudic2004test2gwtgwt") ex = ["prudic2004t2gwtgwt"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - gwfnames = ["flow1", "flow2"] gwtnames = ["transport1", "transport2"] @@ -37,7 +27,7 @@ delr = 405.665 delc = 403.717 top = 100.0 -fname = os.path.join(data_ws, "bot1.dat") +fname = os.path.join(model_path, "bot1.dat") bot0 = np.loadtxt(fname) botm = [bot0] + [bot0 - (15.0 * k) for k in range(1, nlay)] @@ -57,12 +47,12 @@ across_model_mvt_on = True and across_model_mvr_on # setup idomain -fname = os.path.join(data_ws, "idomain1.dat") +fname = os.path.join(model_path, "idomain1.dat") idomain0 = np.loadtxt(fname, dtype=int) idomain = nlay * [idomain0] idomain = np.array(idomain) -fname = os.path.join(data_ws, "lakibd.dat") +fname = os.path.join(model_path, "lakibd.dat") lakibd = np.loadtxt(fname, dtype=int) @@ -353,7 +343,7 @@ def build_gwfgwt_combo( else: fname = "chd_south.dat" chdlist = [] - fname = os.path.join(data_ws, fname) + fname = os.path.join(model_path, fname) print(f"Setting CHD information from: {fname}") for line in open(fname, "r").readlines(): ll = line.strip().split() @@ -383,10 +373,10 @@ def build_gwfgwt_combo( [0, "inflow", 8640.0], ] } - fname = os.path.join(data_ws, f"sfr-packdata-{isfrseg}.dat") + fname = os.path.join(model_path, f"sfr-packdata-{isfrseg}.dat") sfrpd = sfr_packagedata_to_list(fname, gwf) nreaches = len(sfrpd) - fname = os.path.join(data_ws, f"sfr-conndata-{isfrseg}.dat") + fname = os.path.join(model_path, f"sfr-conndata-{isfrseg}.dat") sfrcd = sfr_connectiondata_to_list(fname) print(f"Setting nreaches to {nreaches}") sfr = flopy.mf6.ModflowGwfsfr( @@ -504,9 +494,7 @@ def build_gwfgwt_combo( if icombo == 1: lakpackagedata = [[0, 44.0, nlakecon[0], "lake1"]] # - outlets = [ - [0, 0, -1, "MANNING", 44.5, 3.36493214532915, 0.03, 0.2187500e-02] - ] + outlets = [[0, 0, -1, "MANNING", 44.5, 5.000000, 0.03, 0.2187500e-02]] noutlets = 1 elif icombo == 2: lakpackagedata = [[0, 35.2, nlakecon[0], "lake2"]] @@ -521,7 +509,6 @@ def build_gwfgwt_combo( lak = flopy.mf6.ModflowGwflak( gwf, time_conversion=86400.000, - length_conversion=3.28081, print_stage=True, print_flows=True, stage_filerecord=gwfname + ".lak.bin", @@ -892,18 +879,16 @@ def make_concentration_map(sim, ws): print(f"Creating {fname}") plt.savefig(fname) - return - def eval_results(sim): print("evaluating results...") # these answer files are results from autotest/prudic2004test2 - fname = os.path.join(data_ws, "result_conc_lak1.txt") + fname = os.path.join(model_path, "result_conc_lak1.txt") ans_lak1 = np.loadtxt(fname) - fname = os.path.join(data_ws, "result_conc_sfr3.txt") + fname = os.path.join(model_path, "result_conc_sfr3.txt") ans_sfr3 = np.loadtxt(fname) - fname = os.path.join(data_ws, "result_conc_sfr4.txt") + fname = os.path.join(model_path, "result_conc_sfr4.txt") ans_sfr4 = np.loadtxt(fname) makeplot = False @@ -911,7 +896,7 @@ def eval_results(sim): if arg.lower() == "--makeplot": makeplot = True - ws = exdirs[sim.idxsim] + ws = sim.simpath simfp = flopy.mf6.MFSimulation.load(sim_ws=ws, strict=False) if makeplot: @@ -921,7 +906,7 @@ def eval_results(sim): make_concentration_map(simfp, ws) # ensure concentrations were saved - ws = exdirs[sim.idxsim] + ws = sim.simpath gwfname = gwfnames[0] gwtname = gwtnames[0] @@ -975,39 +960,19 @@ def eval_results(sim): # uncomment when testing # assert False - return - -# - No need to change any code below +@pytest.mark.slow @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_sft01.py b/autotest/test_gwt_sft01.py index 81e75c0bd65..69228d1abcc 100644 --- a/autotest/test_gwt_sft01.py +++ b/autotest/test_gwt_sft01.py @@ -6,26 +6,14 @@ # There is no flow between the stream and the aquifer. import os -import sys +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["sft_01"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -381,7 +369,7 @@ def eval_results(sim): print("evaluating results...") # ensure lake concentrations were saved - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fname = gwtname + ".sft.bin" fname = os.path.join(sim.simpath, fname) @@ -436,39 +424,18 @@ def eval_results(sim): # uncomment when testing # assert False - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_sft01gwtgwt.py b/autotest/test_gwt_sft01gwtgwt.py index 005374a5934..ba63d36a3a2 100644 --- a/autotest/test_gwt_sft01gwtgwt.py +++ b/autotest/test_gwt_sft01gwtgwt.py @@ -16,27 +16,13 @@ # gwt 1 2 3 4 5 6 7 gwtgwt => 1 2 3 4 5 6 7 -import os -import sys - +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["sft01gwtgwt"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) # properties for each model combination lx = 7.0 @@ -499,7 +485,7 @@ def eval_results(sim): print("evaluating results...") # load the simulations - ws = exdirs[sim.idxsim] + ws = sim.simpath sim = flopy.mf6.MFSimulation.load(sim_ws=ws) # construct head and conc for combined models @@ -526,39 +512,18 @@ def eval_results(sim): conc, sfrconc ), "aquifer concentration does not equal sfr concentration" - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_results, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_results, idxsim=idx) - test.run_mf6(sim) - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_results, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_gwt_src01.py b/autotest/test_gwt_src01.py index 4121f4fb4dc..1535cdbd909 100644 --- a/autotest/test_gwt_src01.py +++ b/autotest/test_gwt_src01.py @@ -7,36 +7,15 @@ """ import os -import sys +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["src01a"] xt3d = [False] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" def build_model(idx, dir): @@ -262,17 +241,12 @@ def build_model(idx, dir): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") - try: - cobj = flopy.utils.HeadFile( - fpth, precision="double", text="CONCENTRATION" - ) - conc = cobj.get_data() - except: - assert False, f'could not load data from "{fpth}"' + cobj = flopy.utils.HeadFile(fpth, precision="double", text="CONCENTRATION") + conc = cobj.get_data() # This is the answer to this problem. These concentrations are for # steady state and calculated from F = D * (c1 - c2) / L @@ -281,42 +255,18 @@ def eval_transport(sim): cres, conc ), "simulated concentrations do not match with known solution." - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_ssm01fmi.py b/autotest/test_gwt_ssm01fmi.py index 7c3c83aa145..f25cb062679 100644 --- a/autotest/test_gwt_ssm01fmi.py +++ b/autotest/test_gwt_ssm01fmi.py @@ -4,38 +4,12 @@ # be 100. import os -import shutil +from os.path import join +import flopy import numpy as np -import pytest -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - - -import targets - -exe_name_mf6 = targets.target_dict["mf6"] -exe_name_mf6 = os.path.abspath(exe_name_mf6) - -testdir = "./temp" testgroup = "ssm01" -d = os.path.join(testdir, testgroup) -if os.path.isdir(d): - shutil.rmtree(d) nlay = 1 nrow = 10 @@ -46,14 +20,12 @@ botm = 0.0 -def run_flow_model(): +def run_flow_model(dir, exe): global idomain name = "flow" gwfname = name - wsf = os.path.join(testdir, testgroup, name) - sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=wsf, exe_name=exe_name_mf6 - ) + wsf = join(dir, testgroup, name) + sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=wsf, exe_name=exe) tdis_rc = [(100.0, 1, 1.0), (100.0, 1, 1.0)] nper = len(tdis_rc) tdis = flopy.mf6.ModflowTdis( @@ -194,17 +166,15 @@ def run_flow_model(): errmsg = f"flow model did not terminate successfully\n{buff}" assert success, errmsg - return - -def run_transport_model(): +def run_transport_model(dir, exe): name = "transport" gwtname = name - wst = os.path.join(testdir, testgroup, name) + wst = join(dir, testgroup, name) sim = flopy.mf6.MFSimulation( sim_name=name, version="mf6", - exe_name=exe_name_mf6, + exe_name=exe, sim_ws=wst, continue_=False, ) @@ -338,21 +308,8 @@ def run_transport_model(): ) assert np.all(simulated_concentration == 100.0), errmsg - return - - -def test_ssm01fmi(): - run_flow_model() - run_transport_model() - d = os.path.join(testdir, testgroup) - if os.path.isdir(d): - shutil.rmtree(d) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - # run tests - test_ssm01fmi() +def test_ssm01fmi(function_tmpdir, targets): + mf6 = targets.mf6 + run_flow_model(str(function_tmpdir), mf6) + run_transport_model(str(function_tmpdir), mf6) diff --git a/autotest/test_gwt_ssm02.py b/autotest/test_gwt_ssm02.py index b746e5a07b7..251bd3dc49c 100644 --- a/autotest/test_gwt_ssm02.py +++ b/autotest/test_gwt_ssm02.py @@ -9,35 +9,16 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["ssm02"] laytyp = [1] ss = [1.0e-10] sy = [0.1] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) nlay, nrow, ncol = 1, 1, 1 @@ -239,25 +220,17 @@ def build_model(idx, dir): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name gwfname = "gwf_" + name fpth = os.path.join(sim.simpath, f"{gwfname}.hds") - try: - hobj = flopy.utils.HeadFile(fpth, precision="double") - head = hobj.get_alldata().flatten() - except: - assert False, f'could not load data from "{fpth}"' + hobj = flopy.utils.HeadFile(fpth, precision="double") + head = hobj.get_alldata().flatten() fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") - try: - cobj = flopy.utils.HeadFile( - fpth, precision="double", text="CONCENTRATION" - ) - conc = cobj.get_alldata().flatten() - except: - assert False, f'could not load data from "{fpth}"' + cobj = flopy.utils.HeadFile(fpth, precision="double", text="CONCENTRATION") + conc = cobj.get_alldata().flatten() # calculations times = hobj.get_times() @@ -278,42 +251,18 @@ def eval_transport(sim): assert np.allclose(c, conc_calc, atol=0.001), msg vold = v - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_ssm03.py b/autotest/test_gwt_ssm03.py index d94d3f91ab6..02f8c05fad9 100644 --- a/autotest/test_gwt_ssm03.py +++ b/autotest/test_gwt_ssm03.py @@ -7,24 +7,13 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["ssm03"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) def build_model(idx, dir): @@ -243,28 +232,20 @@ def build_model(idx, dir): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name # load concentration file fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") - try: - cobj = flopy.utils.HeadFile( - fpth, precision="double", text="CONCENTRATION" - ) - conc = cobj.get_data() - except: - assert False, f'could not load data from "{fpth}"' + cobj = flopy.utils.HeadFile(fpth, precision="double", text="CONCENTRATION") + conc = cobj.get_data() # load transport budget file fpth = os.path.join(sim.simpath, f"{gwtname}.cbc") - try: - bobj = flopy.utils.CellBudgetFile( - fpth, - precision="double", - ) - except: - assert False, f'could not load data from "{fpth}"' + bobj = flopy.utils.CellBudgetFile( + fpth, + precision="double", + ) ssmbudall = bobj.get_data(text="SOURCE-SINK MIX") for ssmbud in ssmbudall: @@ -279,42 +260,18 @@ def eval_transport(sim): assert node2 == 1, "node2 location for chd must be 1 (first chd)" assert q < 0.0, "mass flux for chd must be less than zero" - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_ssm04.py b/autotest/test_gwt_ssm04.py index 84485de916e..af29c01539c 100644 --- a/autotest/test_gwt_ssm04.py +++ b/autotest/test_gwt_ssm04.py @@ -13,24 +13,13 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["ssm04"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) nlay, nrow, ncol = 3, 5, 5 idomain_lay0 = [ @@ -413,28 +402,20 @@ def build_model(idx, dir): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name # load concentration file fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") - try: - cobj = flopy.utils.HeadFile( - fpth, precision="double", text="CONCENTRATION" - ) - conc = cobj.get_data() - except: - assert False, f'could not load data from "{fpth}"' + cobj = flopy.utils.HeadFile(fpth, precision="double", text="CONCENTRATION") + conc = cobj.get_data() # load transport budget file fpth = os.path.join(sim.simpath, f"{gwtname}.cbc") - try: - bobj = flopy.utils.CellBudgetFile( - fpth, - precision="double", - ) - except: - assert False, f'could not load data from "{fpth}"' + bobj = flopy.utils.CellBudgetFile( + fpth, + precision="double", + ) ssmbudall = bobj.get_data(text="SOURCE-SINK MIX") times = cobj.get_times() @@ -500,42 +481,18 @@ def eval_transport(sim): istart = istop - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_ssm05.py b/autotest/test_gwt_ssm05.py index e6a84fd536d..0945813cbd9 100644 --- a/autotest/test_gwt_ssm05.py +++ b/autotest/test_gwt_ssm05.py @@ -7,24 +7,13 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["ssm05"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) nlay, nrow, ncol = 3, 5, 5 idomain_lay0 = [ @@ -252,28 +241,20 @@ def build_model(idx, dir): def eval_transport(sim): print("evaluating transport...") - name = ex[sim.idxsim] + name = sim.name gwtname = "gwt_" + name # load concentration file fpth = os.path.join(sim.simpath, f"{gwtname}.ucn") - try: - cobj = flopy.utils.HeadFile( - fpth, precision="double", text="CONCENTRATION" - ) - conc = cobj.get_data() - except: - assert False, f'could not load data from "{fpth}"' + cobj = flopy.utils.HeadFile(fpth, precision="double", text="CONCENTRATION") + conc = cobj.get_data() # load transport budget file fpth = os.path.join(sim.simpath, f"{gwtname}.cbc") - try: - bobj = flopy.utils.CellBudgetFile( - fpth, - precision="double", - ) - except: - assert False, f'could not load data from "{fpth}"' + bobj = flopy.utils.CellBudgetFile( + fpth, + precision="double", + ) ssmbudall = bobj.get_data(text="SOURCE-SINK MIX") times = cobj.get_times() @@ -332,42 +313,18 @@ def eval_transport(sim): istart = istop - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the models - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_transport, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # build the models - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_transport, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_transport, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwt_ssm06.py b/autotest/test_gwt_ssm06.py index 4755fa610f9..1371aec43e2 100644 --- a/autotest/test_gwt_ssm06.py +++ b/autotest/test_gwt_ssm06.py @@ -2,38 +2,11 @@ # See test_gwt_ssm06fmi.py for additional detail on what this test is about. import os -import shutil +import flopy import numpy as np -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - - -import targets - -exe_name_mf6 = targets.target_dict["mf6"] -exe_name_mf6 = os.path.abspath(exe_name_mf6) - -testdir = "./temp" testgroup = "ssm06" -d = os.path.join(testdir, testgroup) -if os.path.isdir(d): - shutil.rmtree(d) - nlay = 1 nrow = 10 @@ -66,13 +39,11 @@ ndv = 0 -def run_flw_and_trnprt_models(): +def run_flw_and_trnprt_models(dir, exe): global idomain gwfname = "gwf-" + testgroup - ws = os.path.join(testdir, testgroup) - sim = flopy.mf6.MFSimulation( - sim_name=testgroup, sim_ws=ws, exe_name=exe_name_mf6 - ) + ws = dir + sim = flopy.mf6.MFSimulation(sim_name=testgroup, sim_ws=ws, exe_name=exe) tdis_rc = [(100.0, 10, 1.0), (100.0, 10, 1.0)] nper = len(tdis_rc) tdis = flopy.mf6.ModflowTdis( @@ -374,20 +345,7 @@ def run_flw_and_trnprt_models(): d0 = np.genfromtxt(fname, names=True, delimiter=",", deletechars="") print(d0.dtype.names) - return - - -def test_ssm06(): - run_flw_and_trnprt_models() - d = os.path.join(testdir, testgroup) - if os.path.isdir(d): - shutil.rmtree(d) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - # run tests - test_ssm06() +def test_ssm06(function_tmpdir, targets): + mf6 = targets.mf6 + run_flw_and_trnprt_models(str(function_tmpdir), mf6) diff --git a/autotest/test_gwt_ssm06fmi.py b/autotest/test_gwt_ssm06fmi.py index 47db31182a9..372b1efd1d4 100644 --- a/autotest/test_gwt_ssm06fmi.py +++ b/autotest/test_gwt_ssm06fmi.py @@ -8,38 +8,11 @@ # separately never threw the error. import os -import shutil +import flopy import numpy as np -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - - -import targets - -exe_name_mf6 = targets.target_dict["mf6"] -exe_name_mf6 = os.path.abspath(exe_name_mf6) - -testdir = "./temp" testgroup = "ssm06fmi" -d = os.path.join(testdir, testgroup) -if os.path.isdir(d): - shutil.rmtree(d) - nlay = 1 nrow = 10 @@ -72,14 +45,12 @@ ndv = 0 -def run_flow_model(): +def run_flow_model(dir, exe): global idomain name = "flow" gwfname = name - wsf = os.path.join(testdir, testgroup, name) - sim = flopy.mf6.MFSimulation( - sim_name=name, sim_ws=wsf, exe_name=exe_name_mf6 - ) + wsf = os.path.join(dir, testgroup, name) + sim = flopy.mf6.MFSimulation(sim_name=name, sim_ws=wsf, exe_name=exe) tdis_rc = [(100.0, 1, 1.0), (100.0, 1, 1.0)] nper = len(tdis_rc) tdis = flopy.mf6.ModflowTdis( @@ -269,17 +240,15 @@ def run_flow_model(): errmsg = f"flow model did not terminate successfully\n{buff}" assert success, errmsg - return - -def run_transport_model(): +def run_transport_model(dir, exe): name = "transport" gwtname = name - wst = os.path.join(testdir, testgroup, name) + wst = os.path.join(dir, testgroup, name) sim = flopy.mf6.MFSimulation( sim_name=name, version="mf6", - exe_name=exe_name_mf6, + exe_name=exe, sim_ws=wst, continue_=False, ) @@ -408,21 +377,9 @@ def run_transport_model(): fname = os.path.join(wst, fname) d0 = np.genfromtxt(fname, names=True, delimiter=",", deletechars="") print(d0.dtype.names) - return - - -def test_ssm06fmi(): - run_flow_model() - run_transport_model() - d = os.path.join(testdir, testgroup) - if os.path.isdir(d): - shutil.rmtree(d) - return - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - # run tests - test_ssm06fmi() +def test_ssm06fmi(function_tmpdir, targets): + mf6 = targets.mf6 + run_flow_model(str(function_tmpdir), mf6) + run_transport_model(str(function_tmpdir), mf6) diff --git a/autotest/test_gwt_uzt01.py b/autotest/test_gwt_uzt01.py index 01946fb5b5d..50f1f482bb9 100644 --- a/autotest/test_gwt_uzt01.py +++ b/autotest/test_gwt_uzt01.py @@ -8,33 +8,13 @@ import os +import flopy import numpy as np import pytest - -try: - import pymake -except: - msg = "Error. Pymake package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install https://github.com/modflowpy/pymake/zipball/master" - raise Exception(msg) - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation ex = ["uzt01a"] -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) -ddir = "data" nlay, nrow, ncol = 15, 1, 1 @@ -341,13 +321,8 @@ def build_model(idx, dir): if id1 < ncv - 1: id2list.append(id1 + 1) for id2 in id2list: - obs1.append( - (f"uzt{id1 + 1}x{id2 + 1}", obstype, id1 + 1, id2 + 1) - ) - obs2 = [ - (f"buzt{i + 1}", obstype, f"myuzt{i + 1}") - for i in range(ncv) - ] + obs1.append((f"uzt{id1 + 1}x{id2 + 1}", obstype, id1 + 1, id2 + 1)) + obs2 = [(f"buzt{i + 1}", obstype, f"myuzt{i + 1}") for i in range(ncv)] uzt_obs[fname] = obs1 + obs2 # append additional obs attributes to obs dictionary @@ -403,8 +378,8 @@ def build_model(idx, dir): def make_plot(sim, obsvals): print("making plots...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath # shows curves for times 2.5, 7.5, 12.6, 17.7 # which are indices 24, 74, 125, and -1 @@ -438,8 +413,8 @@ def make_plot(sim, obsvals): def check_obs(sim): print("checking obs...") - name = ex[sim.idxsim] - ws = exdirs[sim.idxsim] + name = sim.name + ws = sim.simpath sim = flopy.mf6.MFSimulation.load(sim_ws=ws) gwfname = "gwf_" + name gwtname = "gwt_" + name @@ -467,7 +442,9 @@ def check_obs(sim): # print(f" Checking control volume {icv + 1}") if ".concentration.csv" in csvfile: - is_same = np.allclose(conc_ra[f"BUZT{icv + 1}"], conc_uzt[:, icv]) + is_same = np.allclose( + conc_ra[f"BUZT{icv + 1}"], conc_uzt[:, icv] + ) if not is_same: success = False print( @@ -506,16 +483,15 @@ def check_obs(sim): ) assert success, "One or more UZT obs checks did not pass" - return def eval_flow(sim): print("evaluating flow...") - name = ex[sim.idxsim] + name = sim.name gwfname = "gwf_" + name gwtname = "gwt_" + name - ws = exdirs[sim.idxsim] + ws = sim.simpath # check binary grid file fname = os.path.join(ws, gwfname + ".dis.grb") @@ -581,47 +557,22 @@ def eval_flow(sim): # Make plot of obs fpth = os.path.join(sim.simpath, gwtname + ".uzt.obs.concentration.csv") - try: - obsvals = np.genfromtxt(fpth, names=True, delimiter=",") - except: - assert False, f'could not load data from "{fpth}"' - if False: - make_plot(sim, obsvals) - return + obsvals = np.genfromtxt(fpth, names=True, delimiter=",") + + # make_plot(sim, obsvals) -# - No need to change any code below @pytest.mark.parametrize( - "idx, dir", - list(enumerate(exdirs)), + "name", + ex, ) -def test_mf6model(idx, dir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, dir) - - # run the test model - test.run_mf6(Simulation(dir, exfunc=eval_flow, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test model - for idx, dir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, dir) - sim = Simulation(dir, exfunc=eval_flow, idxsim=idx) - test.run_mf6(sim) - - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, 0, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=eval_flow, idxsim=0 + ), + ws, + ) diff --git a/autotest/test_gwtgwt_oldexg.py b/autotest/test_gwtgwt_oldexg.py index 21e91f109d6..48b9ba073cf 100644 --- a/autotest/test_gwtgwt_oldexg.py +++ b/autotest/test_gwtgwt_oldexg.py @@ -1,18 +1,10 @@ import os +import flopy import numpy as np import pytest - -try: - import flopy -except: - msg = "Error. FloPy package is not available.\n" - msg += "Try installing using the following command:\n" - msg += " pip install flopy" - raise Exception(msg) - -from framework import testing_framework -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation # Test compatibility of GWT-GWT with the 'classic' GWF exchange. # It compares the result of a single reference model @@ -38,10 +30,6 @@ ex = ["gwtgwt_oldexg"] use_ifmod = False -exdirs = [] -for s in ex: - exdirs.append(os.path.join("temp", s)) - # some global convenience...: # model names mname_ref = "refmodel" @@ -719,8 +707,6 @@ def compare_gwf_to_ref(sim): errmsg = f"min or max residual too large {res.min()} {res.max()}" assert np.allclose(res, 0.0, atol=1.0e-6), errmsg - return - def compare_gwt_to_ref(sim): print("comparing concentration to single model reference...") @@ -781,41 +767,18 @@ def compare_gwt_to_ref(sim): errmsg = f"min or max residual too large {res.min()} {res.max()}" assert np.allclose(res, 0.0, atol=1.0e-6), errmsg - return - -# - No need to change any code below @pytest.mark.parametrize( - "idx, exdir", - list(enumerate(exdirs)), + "idx, name", + list(enumerate(ex)), ) -def test_mf6model(idx, exdir): - # initialize testing framework - test = testing_framework() - - # build the model - test.build_mf6_models(build_model, idx, exdir) - - # run the test model - test.run_mf6(Simulation(exdir, exfunc=compare_to_ref, idxsim=idx)) - - -def main(): - # initialize testing framework - test = testing_framework() - - # run the test models - for idx, exdir in enumerate(exdirs): - test.build_mf6_models(build_model, idx, exdir) - - sim = Simulation(exdir, exfunc=compare_to_ref, idxsim=idx) - test.run_mf6(sim) - return - - -if __name__ == "__main__": - # print message - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + test = TestFramework() + test.build(build_model, idx, ws) + test.run( + TestSimulation( + name=name, exe_dict=targets, exfunc=compare_to_ref, idxsim=idx + ), + ws, + ) diff --git a/autotest/test_mf6_tmp_simulations.py b/autotest/test_mf6_tmp_simulations.py index c6ee3c22b1a..65600a5ab30 100644 --- a/autotest/test_mf6_tmp_simulations.py +++ b/autotest/test_mf6_tmp_simulations.py @@ -2,9 +2,9 @@ import sys import pytest - from common_regression import get_mf6_ftypes, get_namefiles -from simulation import Simulation +from framework import TestFramework +from simulation import TestSimulation exdir = os.path.join("..", "tmp_simulations") testpaths = os.path.join("..", exdir) @@ -75,9 +75,7 @@ def get_mf6_models(): namefiles = get_namefiles(pth) ftypes = [] for namefile in namefiles: - ftype = get_mf6_ftypes( - namefile, select_packages - ) + ftype = get_mf6_ftypes(namefile, select_packages) if ftype not in ftypes: ftypes += ftype if len(ftypes) > 0: @@ -97,7 +95,7 @@ def get_mf6_models(): return dirs -def run_mf6(sim): +def run_mf6(sim, ws): """ Run the MODFLOW 6 simulation and compare to existing head file or appropriate MODFLOW-2005, MODFLOW-NWT, MODFLOW-USG, or MODFLOW-LGR run. @@ -105,49 +103,16 @@ def run_mf6(sim): """ print(os.getcwd()) src = os.path.join(exdir, sim.name) - dst = os.path.join("temp", sim.name) + dst = os.path.join(ws, sim.name) sim.setup(src, dst) sim.run() sim.compare() - sim.teardown() @pytest.mark.parametrize( - "idx, dir", + "idx, name", list(enumerate(get_mf6_models())), ) -def test_mf6model(idx, dir): - # run the test model - run_mf6(Simulation(dir)) - - -def main(): - # write message - tnam = os.path.splitext(os.path.basename(__file__))[0] - msg = f"Running {tnam} test" - print(msg) - - # get a list of test models to run - dirs = get_mf6_models() - - # run the test model - for dir in dirs: - sim = Simulation(dir) - run_mf6(sim) - - return - - -if __name__ == "__main__": - - print(f"standalone run of {os.path.basename(__file__)}") - - delFiles = True - for idx, arg in enumerate(sys.argv): - if arg.lower() == "--keep": - if len(sys.argv) > idx + 1: - delFiles = False - break - - # run main routine - main() +def test_mf6model(idx, name, function_tmpdir, targets): + ws = str(function_tmpdir) + run_mf6(TestSimulation(name=name, exe_dict=targets), ws) diff --git a/autotest/test_z01_testmodels_mf6.py b/autotest/test_z01_testmodels_mf6.py index a58a918d715..1869f3d9cc2 100644 --- a/autotest/test_z01_testmodels_mf6.py +++ b/autotest/test_z01_testmodels_mf6.py @@ -1,6 +1,6 @@ import pytest from conftest import should_compare -from simulation import Simulation +from simulation import TestSimulation excluded_models = [ "alt_model", @@ -38,9 +38,9 @@ def test_model(function_tmpdir, test_model_mf6, targets, original_regression): if name in excluded_models: pytest.skip(f"Excluding mf6 model: {name}") - sim = Simulation( + sim = TestSimulation( name=name, - exe_dict=targets.as_dict(), + exe_dict=targets, mf6_regression=not original_regression, cmp_verbose=False, make_comparison=should_compare(name, excluded_comparisons, targets), diff --git a/autotest/test_z02_testmodels_mf5to6.py b/autotest/test_z02_testmodels_mf5to6.py index aac388c3b8e..d665cc3922e 100644 --- a/autotest/test_z02_testmodels_mf5to6.py +++ b/autotest/test_z02_testmodels_mf5to6.py @@ -4,7 +4,7 @@ import pytest from common_regression import get_namefiles, model_setup from conftest import should_compare -from simulation import Simulation +from simulation import TestSimulation sfmt = "{:25s} - {}" excluded_models = [ @@ -30,9 +30,9 @@ def test_model( if name in excluded_models: pytest.skip(f"Excluding mf5to6 model: {name}") - sim = Simulation( + sim = TestSimulation( name=exdir.name, - exe_dict=targets.as_dict(), + exe_dict=targets, mf6_regression=not original_regression, cmp_verbose=False, make_comparison=should_compare(name, excluded_comparisons, targets), diff --git a/autotest/test_z03_examples.py b/autotest/test_z03_examples.py index a5db81a0900..fc972e75e6c 100644 --- a/autotest/test_z03_examples.py +++ b/autotest/test_z03_examples.py @@ -1,6 +1,6 @@ import pytest from conftest import should_compare -from simulation import Simulation +from simulation import TestSimulation # skip nested models # ex-gwf-csub-p02c has subdirs like 'es-001', 'hb-100' @@ -59,7 +59,7 @@ def test_scenario(function_tmpdir, example_scenario, targets): for exdir in exdirs: model_name = f"{name}_{exdir.name}" workspace = function_tmpdir / model_name - sim = Simulation( + sim = TestSimulation( name=model_name, exe_dict=targets.as_dict(), mf6_regression=True, diff --git a/autotest/test_z03_largetestmodels.py b/autotest/test_z03_largetestmodels.py index 4631a799baf..81d616c7c3f 100644 --- a/autotest/test_z03_largetestmodels.py +++ b/autotest/test_z03_largetestmodels.py @@ -1,6 +1,6 @@ import pytest from conftest import should_compare -from simulation import Simulation +from simulation import TestSimulation excluded_models = [] excluded_comparisons = { @@ -24,7 +24,7 @@ def test_model( if name in excluded_models: pytest.skip(f"Excluding large mf6 model: {name}") - sim = Simulation( + sim = TestSimulation( name=name, exe_dict=targets.as_dict(), mf6_regression=not original_regression, diff --git a/autotest/update_flopy.py b/autotest/update_flopy.py index 42db0b3539e..60f9874e557 100644 --- a/autotest/update_flopy.py +++ b/autotest/update_flopy.py @@ -1,27 +1,21 @@ +import argparse import importlib import os import shutil import subprocess -from contextlib import contextmanager +from pathlib import Path import flopy +import pytest +from conftest import project_root_path -flopypth = flopy.__path__[0] -print(f"flopy is installed in {flopypth}") - - -@contextmanager -def cwd(path): - oldpwd = os.getcwd() - os.chdir(path) - try: - yield - finally: - os.chdir(oldpwd) +dfn_path = project_root_path / "doc" / "mf6io" / "mf6ivar" / "dfn" +fpy_path = flopy.__path__[0] +print(f"flopy is installed in {fpy_path}") def test_delete_mf6(): - pth = os.path.join(flopypth, "mf6", "modflow") + pth = os.path.join(fpy_path, "mf6", "modflow") files = [ entry for entry in os.listdir(pth) @@ -30,8 +24,9 @@ def test_delete_mf6(): delete_files(files, pth, exclude="mfsimulation.py") +@pytest.mark.order(after="test_delete_mf6") def test_delete_dfn(): - pth = os.path.join(flopypth, "mf6", "data", "dfn") + pth = os.path.join(fpy_path, "mf6", "data", "dfn") files = [ entry for entry in os.listdir(pth) @@ -40,29 +35,31 @@ def test_delete_dfn(): delete_files(files, pth, exclude="flopy.dfn") -def test_copy_dfn(): - pth0 = os.path.join("..", "doc", "mf6io", "mf6ivar", "dfn") +@pytest.mark.order(after="test_delete_dfn") +@pytest.mark.parametrize("path", [dfn_path]) +def test_copy_dfn(path): files = [ entry - for entry in os.listdir(pth0) - if os.path.isfile(os.path.join(pth0, entry)) + for entry in os.listdir(path) + if os.path.isfile(os.path.join(path, entry)) ] - pth1 = os.path.join(flopypth, "mf6", "data", "dfn") + pth1 = os.path.join(fpy_path, "mf6", "data", "dfn") for fn in files: ext = os.path.splitext(fn)[1].lower() if "dfn" in ext: - fpth0 = os.path.join(pth0, fn) + fpth0 = os.path.join(path, fn) fpth1 = os.path.join(pth1, fn) - print(f'copying {fn} from "{pth0}" to "{pth1}"') + print(f'copying {fn} from "{path}" to "{pth1}"') shutil.copyfile(fpth0, fpth1) +@pytest.mark.order(after="test_copy_dfn") def test_create_packages(): # get list of files in mf6/modflow - pth = os.path.join(flopypth, "mf6", "modflow") + pth = os.path.join(fpy_path, "mf6", "modflow") list_files(pth) - pth = os.path.join(flopypth, "mf6", "utils") + pth = os.path.join(fpy_path, "mf6", "utils") fn = "createpackages.py" # determine if createpackages.py exists @@ -71,19 +68,16 @@ def test_create_packages(): exist = os.path.isfile(fpth) assert exist, f'"{fpth}" does not exist' - # run createrpackages.py script + # run createpackages.py script print(f"running...{fn}") - cmd = ["python", fn] - buff, ierr = run_command(cmd, pth) - assert ierr == 0, f"could not run {fn}" - print(f"successfully ran...{fn}") + subprocess.check_output(["python", "createpackages.py"], cwd=pth) # reload flopy print("reloading flopy") importlib.reload(flopy) # get updated list of files in mf6/modflow - pth = os.path.join(flopypth, "mf6", "modflow") + pth = os.path.join(fpy_path, "mf6", "modflow") list_files(pth) @@ -100,7 +94,6 @@ def list_files(pth, exts=["py"]): if ext in exts: idx += 1 print(f" {idx:5d} - {fn}") - return def delete_files(files, pth, allow_failure=False, exclude=None): @@ -124,47 +117,17 @@ def delete_files(files, pth, allow_failure=False, exclude=None): return True -def run_command(argv, pth, timeout=10): - with subprocess.Popen( - argv, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=pth - ) as process: - try: - output, unused_err = process.communicate(timeout=timeout) - buff = output.decode("utf-8") - ierr = process.returncode - except subprocess.TimeoutExpired: - process.kill() - output, unused_err = process.communicate() - buff = output.decode("utf-8") - ierr = 100 - except: - output, unused_err = process.communicate() - buff = output.decode("utf-8") - ierr = 101 - - return buff, ierr - +if __name__ == "__main__": + parser = argparse.ArgumentParser("Update flopy from DFN files") + parser.add_argument( + "-p", "--path", help="path to DFN files", default=str(dfn_path) + ) + args = parser.parse_args() -def main(): - # write message - tnam = os.path.splitext(os.path.basename(__file__))[0] - msg = f"Running {tnam} test" - print(msg) + path = Path(args.path).resolve() + print(f"Updating flopy packages from DFN files in: {path}") - print("deleting existing MODFLOW 6 FloPy files") test_delete_mf6() - print("deleting existing MODFLOW 6 dfn files") test_delete_dfn() - print("copying MODFLOW 6 repo dfn files") - test_copy_dfn() - print("creating MODFLOW 6 packages from repo dfn files") + test_copy_dfn(path) test_create_packages() - - return - - -if __name__ == "__main__": - print(f"standalone run of {os.path.basename(__file__)}") - - # run main routine - main() diff --git a/environment.yml b/environment.yml index 2933f2dc9ac..12633dc18a5 100644 --- a/environment.yml +++ b/environment.yml @@ -23,5 +23,6 @@ dependencies: - pytest - pytest-cases - pytest-dotenv + - pytest-order - pytest-xdist - flaky