Skip to content

Commit

Permalink
Merge pull request #326 from matt-frey/develop
Browse files Browse the repository at this point in the history
Add 3D model
  • Loading branch information
matt-frey authored Feb 14, 2022
2 parents 4f88c6e + f1b82d4 commit 3ffe82c
Show file tree
Hide file tree
Showing 76 changed files with 15,162 additions and 4 deletions.
24 changes: 24 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## How to contribute to EPIC
Hi there. The core developers of EPIC thank you for your contribution. We have some guidelines though which we like you to follow before opening pull request.

<!-- 29 November 2021 -->
<!-- https://stackoverflow.com/questions/11948245/markdown-to-create-pages-and-table-of-contents?page=1&tab=votes#tab-top -->
#### Table of Contents
1. [Unit Testing](#unit-testing)
2. [Coding Style](#coding-style)
2. [Opening a pull request](#pull-request)

### Unit Testing <a name="unit-testing"></a>
Please write unit tests for newly added features and routines. All unit tests are located in the directory `unit-tests`.

### Coding Style <a name="coding-style"></a>
Please follow our coding style when contributing to EPIC.
* use an indentation of 4 spaces
* use lower case letters only
* names of variables and subroutines / functions that consists of multiple words should be separated by underscores, e.g. `this_is_my_subroutine`
* add a whitespace character before and after mathematical operations, e.g. `i = i + 1`
* add a whitespace character after `if` and `while`, e.g. `if (i == 0)`


### Opening a pull request <a name="pull-request"></a>
Developers should fork the main repo and work with the branch `develop`. We only accept pull requests into `develop` of this repository. From time to time we pull all changes in `develop` into `main` and publish a release.
38 changes: 38 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
## EPIC version 0.11.0
#### New features and enhancements
Development of the 3D model (see [#230](https://github.com/matt-frey/epic/issues/230)):
* add eigenvalue solver for real symmetric matrices (see [#229](https://github.com/matt-frey/epic/pull/229))
* add ellipsoid module (see [#233](https://github.com/matt-frey/epic/pull/233))
* add 3D parcel splitting (see [#237](https://github.com/matt-frey/epic/pull/237))
* add 3D parcel initialisation (see [#238](https://github.com/matt-frey/epic/pull/238))
* add 2D FFT (see [#240](https://github.com/matt-frey/epic/pull/240))
* add 3D parcel correction (see [#241](https://github.com/matt-frey/epic/pull/241))
* add 3D parcel merging (see [#243](https://github.com/matt-frey/epic/pull/243))
* add 3D RK4 (see [#244](https://github.com/matt-frey/epic/pull/244))
* add 3D vor2vel (see [#247](https://github.com/matt-frey/epic/pull/247))
* add 3D vorticity tendency calculation (see [#248](https://github.com/matt-frey/epic/pull/248) and [#249](https://github.com/matt-frey/epic/pull/249))
* add 3D adaptive time step estimate (see [#250](https://github.com/matt-frey/epic/pull/250))
* add changelog (see [#255](https://github.com/matt-frey/epic/pull/255))
* add unit tests (see [#242](https://github.com/matt-frey/epic/pull/242), [#246](https://github.com/matt-frey/epic/pull/246))
* [change memory layout](https://github.com/matt-frey/epic/pull/264)
* improve performance (see [#266](https://github.com/matt-frey/epic/pull/266))
* add restarting feature (see [#278](https://github.com/matt-frey/epic/pull/278))
#### Bug fixes
* [fix bug in Straka diagnostics](https://github.com/matt-frey/epic/pull/265)
* [fix calculation of get_delx and get_dely for non-centred domains](https://github.com/matt-frey/epic/pull/279)
## EPIC version 0.10.8
* [fix access of datasets + add colorcet license](https://github.com/matt-frey/epic/pull/321)
## EPIC version 0.10.7
* [fields must be reset](https://github.com/matt-frey/epic/pull/315)
* [fix peref calculation](https://github.com/matt-frey/epic/pull/317)
* [improve Python scripts](https://github.com/matt-frey/epic/pull/318)
* [change setup of parcel correction tests](https://github.com/matt-frey/epic/pull/316)
* [minor plotting changes](https://github.com/matt-frey/epic/pull/319)
## EPIC version 0.10.6
* [more buoyancy and vorticity diagnostics](https://github.com/matt-frey/epic/pull/310)
* [update python scripts](https://github.com/matt-frey/epic/pull/308)
* [do not use data to set dmin and dmax](https://github.com/matt-frey/epic/pull/311)
* [fix genspec writing spectrum](https://github.com/matt-frey/epic/pull/309)
* [fix name clash](https://github.com/matt-frey/epic/pull/312)
* [minval and maxval](https://github.com/matt-frey/epic/pull/313)
* [use heap memory](https://github.com/matt-frey/epic/pull/314)
## EPIC version 0.10.5
* [change order of multi-dimensional arrays](https://github.com/matt-frey/epic/pull/302)
* [remove merger dump](https://github.com/matt-frey/epic/pull/304)
Expand Down
61 changes: 58 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ AC_CONFIG_FILES([
src/Makefile
src/utils/Makefile
src/hdf5/Makefile
src/fft/Makefile
src/2d/Makefile
src/3d/Makefile
models/Makefile
models/2d/Makefile
models/3d/Makefile
analyse/Makefile
unit-tests/Makefile
unit-tests/2d/Makefile
unit-tests/3d/Makefile
python-scripts/Makefile
python-scripts/tools/Makefile
python-scripts/tools/animate/Makefile
Expand Down Expand Up @@ -175,6 +179,10 @@ fi
## "--with" flags
##

## define some default search paths
declare default_lib_paths="/lib:/usr/lib:/lib64:/usr/lib64:/usr/local/lib:$LD_LIBRARY_PATH"
declare default_include_paths="/usr/include:/usr/local/lib:$C_INCLUDE_PATH:$CPLUS_INCLUDE_PATH"

# 11 March 2021
# https://www.gnu.org/software/autoconf/manual/autoconf-2.60/html_node/External-Software.html
AC_ARG_WITH([hdf5],
Expand All @@ -186,27 +194,74 @@ if test -n "${HDF5_DIR}"; then
FCFLAGS="$FCFLAGS -I$HDF5_DIR/include"
LDFLAGS="$LDFLAGS -L$HDF5_DIR/lib"
LIBS="$LIBS -lhdf5_fortran -lhdf5hl_fortran -lhdf5"
else
# check default paths
# 9 Feb 2022
# https://stackoverflow.com/questions/11655770/looping-through-the-elements-of-a-path-variable-in-bash
for path in ${default_lib_paths//:/ }; do
AC_MSG_CHECKING([for hdf5 Fortran libraries in $path])
if test -e "$path/libhdf5hl_fortran.a"; then
HDF5_LIBRARY_DIR="$path"
AC_MSG_RESULT([yes])
break
fi
AC_MSG_RESULT([no])
done

for path in ${default_include_paths//:/ }; do
AC_MSG_CHECKING([for hdf5 Fortran modules in $path])
if test -e "$path/hdf5.mod"; then
HDF5_INCLUDE_DIR="$path"
AC_MSG_RESULT([yes])
break
fi
AC_MSG_RESULT([no])
done

if test -n "${HDF5_LIBRARY_DIR}" && test -n "${HDF5_INCLUDE_DIR}"; then
FCFLAGS="$FCFLAGS -I$HDF5_INCLUDE_DIR"
LDFLAGS="$LDFLAGS -L$HDF5_LIBRARY_DIR"
LIBS="$LIBS -lhdf5_fortran -lhdf5hl_fortran -lhdf5"
else
AC_MSG_ERROR([Cannot find hdf5.
Please export the environment variable HDF5_DIR pointing
to the root directory of hdf5.])
fi
fi

# 11 March 2021
# https://github.com/PhysicsofFluids/AFiD/blob/master/configure.ac#L139
AC_MSG_CHECKING([for hdf5 Fortran library])
AC_MSG_CHECKING([whether we can compile a hdf5 program])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([], [
use hdf5
implicit none
integer :: h5err
call h5open_f(h5err)])],
[hdf5_found=yes],
[hdf5_found=no AC_MSG_ERROR([Cannot find hdf5 Fortran library])])
[hdf5_found=no AC_MSG_ERROR([Cannot compile a hdf5 program])])
AC_MSG_RESULT([$hdf5_found])

#######################################################################################
##
## "--enable" flags
##

ENABLE_DRY_MODE='yes'
ENABLE_3D='no'
AC_ARG_ENABLE([3d],
[AS_HELP_STRING([--enable-3d], [enable 3D model (default=no)])],
[ENABLE_3D=$enableval])

AM_CONDITIONAL([ENABLE_3D], [test "$ENABLE_3D" = "yes"])

AC_MSG_CHECKING([whether we are compiling the 3D model])
if test "x$ENABLE_3D" = "xyes"; then
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi

ENABLE_DRY_MODE='no'
AC_ARG_ENABLE([dry-mode],
[AS_HELP_STRING([--enable-dry-mode], [enable dry mode (default=yes)])],
[ENABLE_DRY_MODE=$enableval])
Expand Down
63 changes: 63 additions & 0 deletions convert_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# transpose the fields too!
import xarray as xr
import argparse
import os.path
import netCDF4 as nc
import numpy as np

parser = argparse.ArgumentParser()

parser.add_argument("input_file_name", type=str)
args = parser.parse_args()
input_file_name = args.input_file_name

file_root, file_ext = os.path.splitext(input_file_name)

if not (file_ext == ".hdf5"):
raise argparse.ArgumentTypeError('Argument filename must end on ".hdf5"')


ds_nc=nc.Dataset(input_file_name)

# set up time array
tstep_keys=[]
for key in ds_nc.groups.keys():
if 'step#' in key:
tstep_keys.append(key)

tlen=len(tstep_keys)
time_array=np.zeros(tlen)
for i_time in range(tlen):
time_array[i_time]=ds_nc.groups[tstep_keys[i_time]].t

# set up spatial arrays
extent=ds_nc.groups['box'].extent
origin=ds_nc.groups['box'].origin
ncells=ds_nc.groups['box'].ncells

x_array=np.linspace(origin[0],origin[0]+extent[0],ncells[0]+1)[:-1]
y_array=np.linspace(origin[1],origin[1]+extent[1],ncells[1]+1)[:-1]
z_array=np.linspace(origin[2],origin[2]+extent[2],ncells[2]+1)
elem_array=range(3)

step0=ds_nc.groups[tstep_keys[0]]

ds_xr = xr.Dataset()

for variable in step0.variables:
n_dims=len(np.shape(step0[variable][:]))
if(n_dims==3):
ds_xr[variable] = xr.DataArray(coords=[time_array, z_array, y_array, x_array], dims=["time", "z","y","x"])
elif(n_dims==4):
ds_xr[variable] = xr.DataArray(coords=[time_array, z_array, y_array, x_array, elem_array], dims=["time", "z","y","x", "index"])

ds_xr['diffB'] = xr.DataArray(coords=[time_array, z_array, y_array, x_array], dims=["time", "z","y","x"])

for i_time in range(tlen):
this_step=ds_nc.groups[tstep_keys[i_time]]
for variable in this_step.variables:
ds_xr[variable][i_time]=np.transpose(this_step[variable][:])
if 'dry buoyancy' in this_step.variables:
ds_xr['diffB'][i_time]=np.transpose(this_step['total buoyancy'][:])-np.transpose(this_step['dry buoyancy'][:])

ds_xr.to_netcdf(file_root + ".nc")
38 changes: 38 additions & 0 deletions examples/moist.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
```
&EPIC

field_file = 'moist.hdf5' ! input field file
field_tol = 1.0e-9 ! tolerance for parcel generation

!
! h5 output info
!
output%h5_field_freq = 50 ![s] write after these many seconds to the field HDF5 file
output%h5_parcel_freq = 50 ![s] write after these many seconds to the parcel HDF5 file
output%h5_parcel_stats_freq = 50 ![s] write after these many seconds to parcel stats HDF5 file
output%h5_field_stats_freq = 50 ![s] write after these many seconds to the field stats HDF5 file
output%h5_write_fields = .true. ! enable / disable field dump
output%h5_write_parcels = .true. ! enable / disable parcel dump
output%h5_write_parcel_stats = .true. ! enable / disable parcel statistics
output%h5_write_field_stats = .true. ! enable / disable field statistics
output%h5_overwrite = .true. ! replace existing HDF5 files
output%h5_basename = 'moist' ! HDF5 output base name

!
! parcel info
!
parcel%n_per_cell = 8 ! initial number of parcels per cell
parcel%lambda_max = 5.0 ! maximum parcel aspect ratio
parcel%min_vratio = 36.0 ! minimum ratio of grid cell volume / parcel volume
parcel%max_vratio = 2.89 ! maximum ratio of grid cell volume / parcel volume
parcel%correction_iters = 2 ! how many parcel correction iterations
parcel%gradient_pref = 1.8 ! gradient correction prefactor
parcel%max_compression = 0.5 ! gradient correction maximum compression

!
! stepper info
!
time%limit = 2000.0 ! time limit (s)
time%alpha = 0.2 ! scaling factor for the strain and buoyancy gradient time step
time%precise_stop = .false. ! time limit exact
/
22 changes: 22 additions & 0 deletions examples/moist.nml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
&MODELS

model = 'MoistPlume'

h5fname = 'moist.hdf5'

box%ncells = 32, 32, 32

box%extent = 6280, 6280, 6280
box%origin = 0, 0, 0

moist%H = 0.8
moist%z_c = 2500
moist%mu = 0.9
moist%z_d = 4000
moist%z_m = 5000
moist%r_plume = 800
moist%e_values = 0.3, -0.4, 0.5
moist%l_condense = 1000.0
moist%q0 = 0.015
moist%theta_l0 = 288.0
/
38 changes: 38 additions & 0 deletions examples/robert3d.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
```
&EPIC

field_file = 'robert3d.hdf5' ! input field file
field_tol = 1.0e-9 ! tolerance for parcel generation

!
! h5 output info
!
output%h5_field_freq = 30 ![s] write after these many seconds to the field HDF5 file
output%h5_parcel_freq = 30 ![s] write after these many seconds to the parcel HDF5 file
output%h5_parcel_stats_freq = 30 ![s] write after these many seconds to parcel stats HDF5 file
output%h5_field_stats_freq = 30 ![s] write after these many seconds to the field stats HDF5 file
output%h5_write_fields = .true. ! enable / disable field dump
output%h5_write_parcels = .true. ! enable / disable parcel dump
output%h5_write_parcel_stats = .true. ! enable / disable parcel statistics
output%h5_write_field_stats = .true. ! enable / disable field statistics
output%h5_overwrite = .true. ! replace existing HDF5 files
output%h5_basename = 'robert3d' ! HDF5 output base name

!
! parcel info
!
parcel%n_per_cell = 8 ! initial number of parcels per cell
parcel%lambda_max = 5.0 ! maximum parcel aspect ratio
parcel%min_vratio = 36.0 ! minimum ratio of grid cell volume / parcel volume
parcel%max_vratio = 2.89 ! maximum ratio of grid cell volume / parcel volume
parcel%correction_iters = 2 ! how many parcel correction iterations
parcel%gradient_pref = 1.8 ! gradient correction prefactor
parcel%max_compression = 0.5 ! gradient correction maximum compression

!
! stepper info
!
time%limit = 1600.0 ! time limit (s)
time%alpha = 0.2 ! scaling factor for the strain and buoyancy gradient time step
time%precise_stop = .false. ! time limit exact
/
27 changes: 27 additions & 0 deletions examples/robert3d.nml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
&MODELS

model = 'Robert'
h5fname = 'robert3d.hdf5'

box%ncells = 32, 32, 32
box%extent = 1000, 1000, 1000
box%origin = -500.0, -500.0, 0.0

robert_flow%n_bubbles = 3

robert_flow%bubbles(1)%dtheta_max = 0.5
robert_flow%bubbles(1)%center = 0.0, 0.0, 300.0
robert_flow%bubbles(1)%radius = 150.0
robert_flow%bubbles(1)%width = 50.0

robert_flow%bubbles(2)%dtheta_max = -0.15
robert_flow%bubbles(2)%center = 60.0, 60.0, 640.0
robert_flow%bubbles(2)%radius = 0.0
robert_flow%bubbles(2)%width = 50.0

robert_flow%bubbles(3)%dtheta_max = -0.35
robert_flow%bubbles(3)%center = -95.0, -80.0, 780.0
robert_flow%bubbles(3)%radius = 0.0
robert_flow%bubbles(3)%width = 70.0

/
Loading

0 comments on commit 3ffe82c

Please sign in to comment.