Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jkennedy-usgs committed Jul 13, 2022
1 parent f38b23b commit 8153c0e
Show file tree
Hide file tree
Showing 378 changed files with 516,963 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Disclaimer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Disclaimer

This software is preliminary or provisional and is subject to revision. It is
being provided to meet the need for timely best science. The software has not
received final approval by the U.S. Geological Survey (USGS). No warranty,
expressed or implied, is made by the USGS or the U.S. Government as to the
functionality of the software and related material nor shall the fact of
release constitute any such warranty. The software is provided on the condition
that neither the USGS nor the U.S. Government shall be held liable for any
damages resulting from the authorized or unauthorized use of the software.
37 changes: 37 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# License

Unless otherwise noted, This project is in the public domain in the United
States because it contains materials that originally came from the United
States Geological Survey, an agency of the United States Department of
Interior. For more information, see the official USGS copyright policy at
http:https://www.usgs.gov/visual-id/credit_usgs.html#copyright

Additionally, we waive copyright and related rights in the work
worldwide through the CC0 1.0 Universal public domain dedication.

## CC0 1.0 Universal Summary

This is a human-readable summary of the
[Legal Code (read the full text)](https://creativecommons.org/publicdomain/zero/1.0/legalcode).

### No Copyright

The person who associated a work with this deed has dedicated the work to
the public domain by waiving all of his or her rights to the work worldwide
under copyright law, including all related and neighboring rights, to the
extent allowed by law.

You can copy, modify, distribute and perform the work, even for commercial
purposes, all without asking permission.

### Other Information

In no way are the patent or trademark rights of any person affected by CC0,
nor are the rights that other persons may have in the work or in how the
work is used, such as publicity or privacy rights.

Unless expressly stated otherwise, the person who associated a work with
this deed makes no warranties about the work, and disclaims liability for
all uses of the work, to the fullest extent permitted by applicable law.
When using or citing the work, you should not imply endorsement by the
author or the affirmer.
63 changes: 62 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,62 @@
# heavy-review
# Heavy
A forward-gravity program for MODFLOW-2005 and MODFLOW-NWT

![gravity calculation](./img/g_calculation.png)

Heavy is a Fortran program for calculating the change in gravity caused by the change in groundwater storage as predicted by a MODFLOW groundwater-flow model.

Gravity change is calculated relative to the initial time step at user-specified locations (e.g., measurement locations). At each location, the gravitational attraction is the sum of the attraction caused by storage change (confined or unconfined) within each model cell and layer.

Heavy is intended to be incorporated into workflows for parameter estimation such as [PEST++](https://www.usgs.gov/software/pest-parameter-estimation-code-optimized-large-environmental-models).

## Running Heavy on Windows:
```
$> Heavy -q
Heavy debug routine
Forsberg gravity, single 100000 x 100000-m layer, 1.0-m thick prism, g = 41.927 uGal
Horizontal infinite slab (2*pi*G), g = 41.928 uGal
Forsberg gravity, single layer 10000 x 10000-m layer composed of 10x10x1-m prisms, g = 41.85 uGal
Gravitational attraction of a 20x20x20-m prism, 100 m deep, vs. an equivalent mass sphere:
Heavy point-mass gravity, g = 6.590618 uGal; Newton's Law (G*m/r^2) = 6.553962 uGal
Process returned 0 (0x0) execution time : 0.585 s
Press any key to continue.
```
(Copy /bin/Heavy.exe to /test/aac)
```
$> Heavy model1_hvy.nam
HEAVY-0.0.2 2021-09-10
U.S. GEOLOGICAL SURVEY MODELING TOOL FOR
THE FORWARD MODELING OF MICROGRAVITY WITH MODFLOW
Using NAME file: model1_hvy.nam
Run start date and time (yyyy/mm/dd hh:mm:ss): 2021/12/17 13:33:49
CALCULATING GRAVITY FOR ALL LAYERS
Single Precision Binary Head file
READ HEAD FOR PERIOD 1 STEP 1 PERTIM = 1.000000E+00 TOTIM = 1.000000E+00
READ HEAD FOR PERIOD 1 STEP 1 PERTIM = 1.000000E+00 TOTIM = 1.000000E+00
...
READ HEAD FOR PERIOD 20 STEP 1 PERTIM = 1.000000E+00 TOTIM = 7.600000E+01
READ HEAD FOR PERIOD 21 STEP 1 PERTIM = 1.000000E+00 TOTIM = 7.700000E+01
Elapsed Run Time: 6.859 seconds
```

**See /doc/User Guide.docx for information on running Heavy**

## Compiling Heavy:

**Windows**
There is a compiled executable in the /bin/Release directory.

Heavy has been compiled on Windows using the Code::Blocks IDE with the gfortran compiler, and using Visual Studio 2019 with the Intel oneAPI Fortran compiler. The latter is somewhat faster but more difficult to compile a standalone executable.

**Linux**
1) Install pymake: ```pip install --user https://github.com/modflowpy/pymake/zipball/master```

2) Compile:
```python -m pymake ./src ./bin/heavy -mc```

This software is preliminary or provisional and is subject to revision. It is being provided to meet the need for timely best science. The software has not received final approval by the U.S. Geological Survey (USGS). No warranty, expressed or implied, is made by the USGS or the U.S. Government as to the functionality of the software and related material nor shall the fact of release constitute any such warranty. The software is provided on the condition that neither the USGS nor the U.S. Government shall be held liable for any damages resulting from the authorized or unauthorized use of the software.
66 changes: 66 additions & 0 deletions autotest/make_gfortran.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#! /usr/bin/env python
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'
print(msg)
raise Exception()
import os
import shutil
import platform


def copytree(src, dst, symlinks=False, ignore=None):
for item in os.listdir(src):
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
shutil.copytree(s, d, symlinks, ignore)
else:
shutil.copy2(s, d)


def cleanup(srcdir, tempdir):
"""
Method to copy source code and cleanup the mfnwt code base
for gfortran compilation.
"""
if os.path.isdir(tempdir):
shutil.rmtree(tempdir)
os.makedirs(tempdir)
copytree(srcdir, "./temp")
# files = ["AACv4.hvy", "AACv4.lst", "AACv4.out", "Heavy.cbp",
# "Heavy.depend", "Heavy.layout"]
# for f in files:
# os.remove(os.path.join(tempdir, f))
return tempdir


if __name__ == "__main__":

args = pymake.parser()

srcdir = args.srcdir

srcdir = cleanup(srcdir, "./temp")

args.subdirs = False

args.makefile = False

#call main -- note that this form allows main to be called
#from python as a function.
try:
pymake.main(srcdir, args.target, args.fc, args.cc, args.makeclean,
args.expedite, args.dryrun, False, args.debug,
args.subdirs, "--static", arch=args.arch,
makefile=args.makefile)
except AttributeError:
pymake.main(srcdir, args.target, args.fc, args.cc, args.makeclean,
args.expedite, args.dryrun, False, args.debug,
args.subdirs, "--static", arch=args.arch,
makefile=args.makefile)

shutil.rmtree(srcdir)
2 changes: 2 additions & 0 deletions autotest/make_linux_gfortran.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gfortran --version
python make_gfortran.py -fc gfortran -ff='-std=legacy' -sd -mc ../src heavy
4 changes: 4 additions & 0 deletions autotest/make_win_gfortran.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set PATH=%PATH%;C:\MinGW\bin
gfortran --version
python make_gfortran.py -fc gfortran -sd -mc ..\src heavy.exe
pause
60 changes: 60 additions & 0 deletions autotest/test_000.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# all test modules should be in a file that starts with the name test.
import os
import shutil
import pandas
import numpy as np

def test_py():
cd = os.getcwd()
os.chdir(os.path.join('..','python'))
print("Heavy test: Python All American Canal model")
os.system('python model1_run.py')
os.chdir(cd)
assert True

def test_aac_model():
cd = os.getcwd()
print("Heavy test: All American Canal model")
os.chdir(os.path.join('..','test','aac'))
os.system(r'..\..\autotest\heavy model1_hvy.nam')
os.chdir(cd)
assert True

def test_py_vs_fortran():
cd = os.getcwd()
print("Heavy test: Comparing Python output to Fortran output")
os.chdir(os.path.join('..','test','aac'))
py_data = pandas.read_csv('sim_py.grav')
f_data = pandas.read_csv('model1.out', delim_whitespace=True, header=0, names=['Station','kper','kstp','totim','g','d2'])
for station in py_data['Station'].unique():
dp = py_data[py_data['Station'] == station]['g'].reset_index(drop=True)
df = f_data[f_data['Station'] == 'G' + station]['g'].reset_index(drop=True)
mse = np.sqrt(((df - dp) ** 2).mean())
print(f'mse, {station}: {mse:.3f}')
assert mse < 0.15
os.chdir(cd)

def test_abq_model():
cd = os.getcwd()
print("Heavy test: Rio Grande Valley transient model")
os.chdir(os.path.join('..','test','abq','2013y_parent'))
os.system(r'..\..\..\autotest\heavy -g 6 tran_hvy.nam')
os.chdir(cd)

def test_truxton_model():
cd = os.getcwd()
print("Heavy test: Truxton Basin Hydrologic Model Xhigh Qhigh scenario")
os.chdir(os.path.join('..','test','truxton','tbhm_tr_Xhigh_Qhigh'))
os.system(r'..\..\..\autotest\heavy -g 6 tbhm_tr_Xhigh_Qhigh_hvy.nam')
os.chdir(cd)

def test_setup():
tempdir = os.path.join('.', 'temp')
if os.path.isdir(tempdir):
shutil.rmtree(tempdir)
os.mkdir(tempdir)
return


if __name__ == "__main__":
test_setup()
Binary file added bin/Heavy.exe
Binary file not shown.
Binary file added doc/Manuscript.docx
Binary file not shown.
Binary file added doc/User Guide.docx
Binary file not shown.
Binary file added img/g_calculation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8153c0e

Please sign in to comment.