From c8bfe39ad5ea8a48bbbcea95719cc728daa15a03 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:05:13 +0000 Subject: [PATCH 01/24] Add .gitlab-ci.yml --- .gitlab-ci.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..a2e1136 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,12 @@ +image: debian + +stages: + - build + +build: + stage: build + script: cd ./build/ && cp -al make.default make.config && cp -al ./hosts/default ./hosts/$HOSTNAME && cd ../ && make -C ./build > build.log + artifacts: + paths: + - build.log + expire_in: 20 minutes \ No newline at end of file From 090c4d7f48221b62bcbc4f73e8d0deae217c88f9 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:12:31 +0000 Subject: [PATCH 02/24] Update .gitlab-ci.yml --- .gitlab-ci.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a2e1136..3808a04 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,6 +5,10 @@ stages: build: stage: build + before_script: + - sudo apt-get update + - sudo apt-get install make + script: cd ./build/ && cp -al make.default make.config && cp -al ./hosts/default ./hosts/$HOSTNAME && cd ../ && make -C ./build > build.log artifacts: paths: From 3ecfc9bf92d438521cd133a65c9baa5284ffe9c9 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:15:49 +0000 Subject: [PATCH 03/24] Update .gitlab-ci.yml --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3808a04..5dfc99f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,8 +6,8 @@ stages: build: stage: build before_script: - - sudo apt-get update - - sudo apt-get install make + - apt-get update + - apt-get install make gfortran libhdf5-dev script: cd ./build/ && cp -al make.default make.config && cp -al ./hosts/default ./hosts/$HOSTNAME && cd ../ && make -C ./build > build.log artifacts: From 59268f392f7dc2f64c2ade89dec2a9a03bdd1daf Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:18:41 +0000 Subject: [PATCH 04/24] Update .gitlab-ci.yml --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 5dfc99f..d0275b2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,8 +6,8 @@ stages: build: stage: build before_script: - - apt-get update - - apt-get install make gfortran libhdf5-dev + - apt-get -q update + - apt-get -q -y install make gfortran libhdf5-dev script: cd ./build/ && cp -al make.default make.config && cp -al ./hosts/default ./hosts/$HOSTNAME && cd ../ && make -C ./build > build.log artifacts: From 41b2f56b3fe5f0040a90b6bca76626c00a7339a3 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:23:39 +0000 Subject: [PATCH 05/24] Update .gitlab-ci.yml --- .gitlab-ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d0275b2..ff2f508 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,8 +9,8 @@ build: - apt-get -q update - apt-get -q -y install make gfortran libhdf5-dev - script: cd ./build/ && cp -al make.default make.config && cp -al ./hosts/default ./hosts/$HOSTNAME && cd ../ && make -C ./build > build.log - artifacts: - paths: - - build.log - expire_in: 20 minutes \ No newline at end of file + script: + - cd ./build/ + - cp -al make.default make.config + - cp -al ./hosts/default ./hosts/$HOSTNAME + - make -C ./build From c4c3053d568f3c06c2960e7a553598275267ab8e Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:24:50 +0000 Subject: [PATCH 06/24] Update .gitlab-ci.yml --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ff2f508..faa9daf 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,4 +13,4 @@ build: - cd ./build/ - cp -al make.default make.config - cp -al ./hosts/default ./hosts/$HOSTNAME - - make -C ./build + - make From b2f6e9ef0bf42731ea33aa56596e0bb83772e611 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:26:36 +0000 Subject: [PATCH 07/24] Update .gitlab-ci.yml --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index faa9daf..a44329e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,4 +13,5 @@ build: - cd ./build/ - cp -al make.default make.config - cp -al ./hosts/default ./hosts/$HOSTNAME + - gfortan --version - make From fa6983764d94a20f1acdba28abc5e3ee3fe4376c Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:28:00 +0000 Subject: [PATCH 08/24] Update .gitlab-ci.yml --- .gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a44329e..a4406d9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,12 +6,12 @@ stages: build: stage: build before_script: - - apt-get -q update - - apt-get -q -y install make gfortran libhdf5-dev + - apt-get -q=2 update + - apt-get -q=2 -y install make gfortran libhdf5-dev script: - cd ./build/ - cp -al make.default make.config - cp -al ./hosts/default ./hosts/$HOSTNAME - - gfortan --version + - gfortran --version - make From 939290082ea52283e66ea467624cc20bb159462f Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:32:41 +0000 Subject: [PATCH 09/24] Update .gitlab-ci.yml --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a4406d9..800cbb8 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,5 +13,6 @@ build: - cd ./build/ - cp -al make.default make.config - cp -al ./hosts/default ./hosts/$HOSTNAME - - gfortran --version + - make makedeps + - cat makedeps - make From 878e2896a46b73f302f1c5d083e2d92a9a10f27d Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:35:40 +0000 Subject: [PATCH 10/24] Update .gitlab-ci.yml --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 800cbb8..9195f25 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,7 +7,7 @@ build: stage: build before_script: - apt-get -q=2 update - - apt-get -q=2 -y install make gfortran libhdf5-dev + - apt-get -q=2 -y install gawk make gfortran libhdf5-dev script: - cd ./build/ From ea19a97f1a5e004426b18119011407feaee7181c Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:48:14 +0000 Subject: [PATCH 11/24] Update .gitlab-ci.yml --- .gitlab-ci.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9195f25..7c90df4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,6 +13,4 @@ build: - cd ./build/ - cp -al make.default make.config - cp -al ./hosts/default ./hosts/$HOSTNAME - - make makedeps - - cat makedeps - - make + - HDF5DIR=/usr/include/hdf5/serial make From 92bee03c1e748f5e0892ddd268e2a7b0d25c5c7e Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:54:58 +0000 Subject: [PATCH 12/24] Update .gitlab-ci.yml --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7c90df4..4cda888 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,4 +13,5 @@ build: - cd ./build/ - cp -al make.default make.config - cp -al ./hosts/default ./hosts/$HOSTNAME - - HDF5DIR=/usr/include/hdf5/serial make + - export HDF5DIR=/usr/lib/x86_64-linux-gnu/hdf5/serial/ + - make From 16eb1fc0deec0df4a94536ab6d5fdd7b2e2b5f22 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:56:49 +0000 Subject: [PATCH 13/24] Update .gitlab-ci.yml --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4cda888..d83c42e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -13,5 +13,5 @@ build: - cd ./build/ - cp -al make.default make.config - cp -al ./hosts/default ./hosts/$HOSTNAME - - export HDF5DIR=/usr/lib/x86_64-linux-gnu/hdf5/serial/ + - export HDF5DIR=/usr/lib/x86_64-linux-gnu/hdf5/serial - make From 905e4caa5d87574ea1256dec81f202214998ffc7 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 21:03:18 +0000 Subject: [PATCH 14/24] Update .gitlab-ci.yml --- .gitlab-ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d83c42e..3894bf3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -6,8 +6,8 @@ stages: build: stage: build before_script: - - apt-get -q=2 update - - apt-get -q=2 -y install gawk make gfortran libhdf5-dev + - apt-get -q update + - apt-get -q -y install gawk make gfortran libhdf5-dev libopenmpi-dev script: - cd ./build/ @@ -15,3 +15,5 @@ build: - cp -al ./hosts/default ./hosts/$HOSTNAME - export HDF5DIR=/usr/lib/x86_64-linux-gnu/hdf5/serial - make + - make clean + - make MPI=Y From fccffe864293b98ec0dd2c0af57c453804c8c523 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 21:36:50 +0000 Subject: [PATCH 15/24] Add CHANGELOG --- CHANGELOG.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..2575a22 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,13 @@ +# 2019-10-04 No version yet. ## +---- + +- support for rectangular adaptive domain in 2D and 3D; +- support for hydrodynamical (HYDRO) and magnetohydrodynamical (MHD) equations, both in classical and relativistic formulations; +- support for adiabatic (ADI) and isothermal (ISO) equation of state; +- support for viscosity and resistivity source terms; +- support for passive scalars; +- time integration using Euler and 2nd order Runge-Kutta methods or up to 4th order Stron Stability Preserving Runge-Kutta; +- a number of spatial interpolation using 2nd order TVD methods, up to 9th order Monotonicity-Preserving; +- HLL-family of approximate Riemann solvers (HLL, HLLC, and HLLD); +- GLM scheme for the induction equation; +- MPI parallelization; \ No newline at end of file From bc288e88f4c9a419d28923ef7b2d7456ef7f6a61 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:07:31 -0300 Subject: [PATCH 16/24] Add more compilation tests to .gitlab-ci.yml Signed-off-by: Grzegorz Kowal --- .gitlab-ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3894bf3..c861d3e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -14,6 +14,10 @@ build: - cp -al make.default make.config - cp -al ./hosts/default ./hosts/$HOSTNAME - export HDF5DIR=/usr/lib/x86_64-linux-gnu/hdf5/serial - - make + - make MPI=N NDIMS=2 - make clean - - make MPI=Y + - make MPI=Y NDIMS=3 + - make clean + - make MPI=Y NDIMS=2 + - make clean + - make MPI=Y NDIMS=3 From 2bda9dd28eedb5affe6d198152063b5bde77fe95 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 4 Oct 2019 20:10:38 -0300 Subject: [PATCH 17/24] Fix one compilation test in .gitlab-ci.yml Signed-off-by: Grzegorz Kowal --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c861d3e..284d0ef 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,7 +16,7 @@ build: - export HDF5DIR=/usr/lib/x86_64-linux-gnu/hdf5/serial - make MPI=N NDIMS=2 - make clean - - make MPI=Y NDIMS=3 + - make MPI=N NDIMS=3 - make clean - make MPI=Y NDIMS=2 - make clean From 7a97e2ea84c53e1e1fa1e4f9978289411fbfe2d3 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Sat, 5 Oct 2019 13:22:36 +0000 Subject: [PATCH 18/24] Initial Bitbucket Pipelines configuration --- bitbucket-pipelines.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 bitbucket-pipelines.yml diff --git a/bitbucket-pipelines.yml b/bitbucket-pipelines.yml new file mode 100644 index 0000000..003e634 --- /dev/null +++ b/bitbucket-pipelines.yml @@ -0,0 +1,25 @@ +# This is a sample build configuration for Other. +# Check our guides at https://confluence.atlassian.com/x/5Q4SMw for more examples. +# Only use spaces to indent your .yml configuration. +# ----- +# You can specify a custom docker image from Docker Hub as your build environment. +image: atlassian/default-image:2 + +pipelines: + default: + - step: + name: Build + script: + - apt-get -q update + - apt-get -q -y install gawk make gfortran libhdf5-dev libopenmpi-dev + - cd ./build + - cp -al make.default make.config + - cp -al ./hosts/default ./hosts/$HOSTNAME + - export HDF5DIR=/usr/lib/x86_64-linux-gnu/hdf5/serial + - make MPI=N NDIMS=2 + - make clean + - make MPI=N NDIMS=3 + - make clean + - make MPI=Y NDIMS=2 + - make clean + - make MPI=Y NDIMS=3 \ No newline at end of file From ec6ea2cbf7864cda5f1a4f7a1b7f5dff85c5dd1a Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Sun, 6 Oct 2019 01:15:30 +0000 Subject: [PATCH 19/24] Update README.md --- README.md | 63 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 9567e46..50c98ab 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,11 @@ --------------------------------------------------------------------------------- + # **The AMUN Code** -## Copyright (C) 2008-2019 Grzegorz Kowal ## --------------------------------------------------------------------------------- +## Copyright (C) 2008-2019 Grzegorz Kowal AMUN is a parallel code to perform numerical simulations in fluid approximation on uniform or non-uniform (adaptive) meshes. The goal in developing this code is to create a solid framework for simulations with support for number of numerical -methods which can be selected in an easy way through the parameter file. The +methods which can be selected in an easy way through a parameter file. The following features are already implemented: * hydrodynamic and magnetohydrodynamic set of equations (HD and MHD), @@ -18,11 +17,13 @@ following features are already implemented: * 2nd order TVD interpolation with number of limiters and higher order reconstructions, * Riemann solvers of Roe- and HLL-types (HLL, HLLC, and HLLD), -* periodic and open boundary conditions, +* standard boundary conditions: periodic, open, reflective, hydrostatic, etc. * viscous and resistive source terms, +* suppor for passive scalars (up to 100), * data stored in the HDF5 format, * MPI parallelization, -* completely written in Fortran 2003. +* completely written in Fortran 2003, +* Python interface to read data. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -46,12 +47,16 @@ Developers Requirements ============ -* Fortran 2003 compiler (tested compilers include - [GNU Fortran](http://gcc.gnu.org/fortran/) version 4.5 or newer, - [Intel Fortran](https://software.intel.com/en-us/fortran-compilers) compiler - version 9.0 or newer) -* [HDF5 libraries](http://www.hdfgroup.org/HDF5/) version 1.8 or newer. -* [OpenMPI](https://www.open-mpi.org/) version 1.8 or newer for parallel runs. +* Fortran 2003 compiler, tested compilers include: + - [GNU Fortran](https://gcc.gnu.org/fortran/) version 4.5 or newer, + - [PGI Community Edition](https://www.pgroup.com/products/community.htm), + version 18.10 or newer, + - [Intel Fortran](https://software.intel.com/en-us/fortran-compilers) + compiler version 9.0 or newer. +* [HDF5 libraries](https://www.hdfgroup.org/solutions/hdf5/), tested with + version 1.8 or newer. +* [OpenMPI](https://www.open-mpi.org/) for parallel runs, tested with version + 1.8 or newer. Environment Variables @@ -65,11 +70,15 @@ the HDF5 libraries have been installed. Compilation =========== -1. Clone the AMUN source code: `git clone https://bitbucket.org/amunteam/amun-code.git`, - or unpack the archive downloaded from page +1. Clone the AMUN source code: + - from Bitbucket: + `git clone https://grzegorz_kowal@bitbucket.org/amunteam/amun-code.git`, + - from GitLab: + `git clone https://gitlab.com/gkowal/amun-code.git` + - or unpack the archive downloaded from page [Downloads](https://bitbucket.org/amunteam/amun-code/downloads/). 2. Go to directory **build/hosts/** and copy file **default** to a new file named - exactly as your host name (name returned by command `hostname`). + exactly as your host name, i.e. `cp default $HOSTNAME`. 3. Customize your compiler and compilation options in your new host file. 4. Go up to directory **build/** and copy file **make.default** to **make.config**. 5. Customize compilation time options in **make.config**. @@ -80,16 +89,18 @@ Compilation Usage ===== -In order to run some test problems you can simply copy corresponding parameter -from directory **problems/** to the location when you wish to run your test. -Copy the executable file **amun.x** compiled earlier to the same directory. If -you provide option _-i _, the code will know that the parameters -have to be read from file __. If you don't provide this option, -the code will assume that the parameters are stored in file **params.in** in the -same director. +In order to run some test problems you can simply copy the problem parameter +file from directory **problems/** to the location where you wish to run your +test. Copy the executable file **amun.x** from the **build/** directory compiled +earlier. If you provide option _-i _, the code will know that +parameters have to be read from file __. If you don't provide +this option, the code assumes that the parameters are stored in file +**params.in** in the same director. -In order to run serial version, type in your terminal: `amun.x -i params.in`. +In order to run serial version, just type in your terminal: + `./amun.x -i ./params.in`. -In order to run the parallel version (after compiling the code with MPI -version), type in your terminal: `mpirun -n N ./amun.x -i params.in`, where N is -the number of processors. +In order to run parallel version (after compiling the code with MPI support), +type in your terminal: + `mpirun -n N ./amun.x -i ./params.in`, +where N is the number of processors to use. \ No newline at end of file From 325208559ecb87e6808f0de55c5bd4b578ff1fc7 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 22 Nov 2019 17:39:49 -0300 Subject: [PATCH 20/24] PYTHON: Rewrite amun_compatible(). Signed-off-by: Grzegorz Kowal --- python/amun.py | 44 +++++++++++++++++--------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/python/amun.py b/python/amun.py index f3591f1..e764fae 100644 --- a/python/amun.py +++ b/python/amun.py @@ -37,6 +37,7 @@ import numpy as np import os.path as op import sys + def amun_compatible(fname): ''' Subroutine checks if the HDF5 file is AMUN compatible. @@ -47,39 +48,28 @@ def amun_compatible(fname): Return values: - ret - True or False; + True or False; Examples: comp = amun_compatible('p000010_00000.h5') ''' - try: - f = h5.File(fname, 'r') - - # check if the file is written in the AMUN format or at least contains - # necessary groups - # - ret = True - if 'code' in f.attrs: - if f.attrs['code'].astype(str) != "AMUN": - print("'%s' contains attribute 'code'", \ - " but it is not set to 'AMUN'!" % fname) - ret = False - elif not 'attributes' in f or \ - not 'coordinates' in f or \ - not 'variables' in f: - print("'%s' misses one of these groups: ", \ - "'attributes', 'coordinates' or 'variables'!" % fname) - ret = False - - f.close() - - except: - print("It seems '%s' is not an HDF5 file!" % fname) - ret = False - - return ret + with h5.File(fname, 'r') as f: + if 'codes' in f.attrs: + if f.attrs['code'].astype(str) == "AMUN": + return True + else: + print("'%s' contains attribute 'code'," % fname, \ + " but it is not 'AMUN'!") + return False + elif 'attributes' in f and 'coordinates' in f and \ + 'variables' in f: + return True + else: + print("'%s' misses one of these groups:" % fname, \ + "'attributes', 'coordinates' or 'variables'!") + return False def amun_attribute(fname, aname): From ed8e606d1525c891fb968a7e45e5366bb3c4d0fe Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 22 Nov 2019 17:46:10 -0300 Subject: [PATCH 21/24] PYTHON: Rewrite amun_attribute(). Signed-off-by: Grzegorz Kowal --- python/amun.py | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/python/amun.py b/python/amun.py index e764fae..8bf1d4c 100644 --- a/python/amun.py +++ b/python/amun.py @@ -83,7 +83,7 @@ def amun_attribute(fname, aname): Return values: - ret - the value of the attribute; + ret - the value of the attribute or None; Examples: @@ -93,27 +93,17 @@ def amun_attribute(fname, aname): if not amun_compatible(fname): return False - try: - f = h5.File(fname, 'r') - g = f['attributes'] - - if aname in g.attrs: - attr = g.attrs[aname] + with h5.File(fname, 'r') as f: + if aname in f['attributes'].attrs: + attr = f['attributes'].attrs[aname] if attr.dtype.type is np.string_: ret = np.squeeze(attr).astype(str) else: ret = np.squeeze(attr) + return ret else: - print("Attribute '%s' cannot be retrieved from '%s'!" % (aname, fname)) - ret = False - - f.close() - - except: - print("Attribute '%s' cannot be retrieved from '%s'!" % (aname, fname)) - ret = False - - return ret + print("Attribute '%s' cannot be found in '%s'!" % (aname, fname)) + return None def amun_coordinate(fname, iname): From 4f809ce96d9d97174e6a0eb185f29e9b9e5abf8a Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 22 Nov 2019 17:48:13 -0300 Subject: [PATCH 22/24] PYTHON: Rewrite amun_coordinate(). Signed-off-by: Grzegorz Kowal --- python/amun.py | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/python/amun.py b/python/amun.py index 8bf1d4c..0b283dd 100644 --- a/python/amun.py +++ b/python/amun.py @@ -91,7 +91,7 @@ def amun_attribute(fname, aname): ''' if not amun_compatible(fname): - return False + return None with h5.File(fname, 'r') as f: if aname in f['attributes'].attrs: @@ -117,7 +117,7 @@ def amun_coordinate(fname, iname): Return values: - ret - the values of the item; + ret - the value of the item or None; Examples: @@ -125,29 +125,14 @@ def amun_coordinate(fname, iname): ''' if not amun_compatible(fname): - return False + return None - try: - f = h5.File(fname, 'r') - g = f['coordinates'] - - if iname in g: - item = g[iname] - if item.dtype.type is np.string_: - ret = np.squeeze(item).astype(str) - else: - ret = np.squeeze(item) + with h5.File(fname, 'r') as f: + if iname in f['coordinates']: + return np.array(f['coordinates'][iname]) else: - print("Coordinate item '%s' cannot be retrieved from '%s'!" % (iname, fname)) - ret = False - - f.close() - - except: - print("Coordinate item '%s' cannot be retrieved from '%s'!" % (iname, fname)) - ret = False - - return ret + print("Coordinate item '%s' not found in group 'coordinate' of '%s'!" % (iname, fname)) + return None def amun_dataset(fname, vname, shrink = 1, progress = False): From 802eb9234f129e5728e58a4c8d1ded038c3c12dc Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 22 Nov 2019 18:09:47 -0300 Subject: [PATCH 23/24] PYTHON: Rewrite amun_dataset(). Signed-off-by: Grzegorz Kowal --- python/amun.py | 248 ++++++++++++++++++++++++------------------------- 1 file changed, 121 insertions(+), 127 deletions(-) diff --git a/python/amun.py b/python/amun.py index 0b283dd..7e8460c 100644 --- a/python/amun.py +++ b/python/amun.py @@ -157,138 +157,138 @@ def amun_dataset(fname, vname, shrink = 1, progress = False): ''' if not amun_compatible(fname): - return False + return None - try: - dname = op.dirname(fname) + dname = op.dirname(fname) - if progress: - sys.stdout.write("Data file path:\n '%s'\n" % (dname)) + if progress: + sys.stdout.write("Data file path:\n '%s'\n" % (dname)) - # get attributes necessary to reconstruct the domain - # - eqsys = amun_attribute(fname, 'eqsys') - eos = amun_attribute(fname, 'eos') - nr = amun_attribute(fname, 'isnap') - nc = amun_attribute(fname, 'nprocs') - nl = amun_attribute(fname, 'nleafs') - if eos == 'adi': - gm = amun_attribute(fname, 'gamma') + # get attributes necessary to reconstruct the domain + # + eqsys = amun_attribute(fname, 'eqsys') + eos = amun_attribute(fname, 'eos') + nr = amun_attribute(fname, 'isnap') + nc = amun_attribute(fname, 'nprocs') + nl = amun_attribute(fname, 'nleafs') + if eos == 'adi': + gm = amun_attribute(fname, 'gamma') - # prepare array to hold data - # - ndims = amun_attribute(fname, 'ndims') - nn = amun_attribute(fname, 'ncells') - bm = np.array([nn, nn, nn]) - if ndims == 2: - bm[2] = 1 - ng = amun_attribute(fname, 'nghosts') - ml = amun_attribute(fname, 'maxlev') - f = h5.File(fname, 'r') - if 'rdims' in f['attributes'].attrs: - rm = amun_attribute(fname, 'rdims') - elif 'bdims' in f['attributes'].attrs: - rm = amun_attribute(fname, 'bdims') - else: - rm = amun_attribute(fname, 'domain_base_dims') - f.close() + # get block dimensions and the maximum level + # + ndims = amun_attribute(fname, 'ndims') + nn = amun_attribute(fname, 'ncells') + bm = np.array([nn, nn, nn]) + if ndims == 2: + bm[2] = 1 + ng = amun_attribute(fname, 'nghosts') + ml = amun_attribute(fname, 'maxlev') - # build the list of supported variables - # - variables = [] - f = h5.File(fname, 'r') + # get the base block dimensions + # + rm = amun_attribute(fname, 'bdims') + if rm is None: + rm = amun_attribute(fname, 'domain_base_dims') + if rm is None: + rm = amun_attribute(fname, 'rdims') + if rm is None: + return None + + # build the list of supported variables + # + variables = [] + with h5.File(fname, 'r') as f: for var in f['variables'].keys(): variables.append(var) - f.close() - # add derived variables if possible - # - variables.append('level') - if 'velx' in variables and 'vely' in variables and 'velz' in variables: - variables.append('velo') - variables.append('divv') - variables.append('vort') - if 'magx' in variables and 'magy' in variables and 'magz' in variables: - variables.append('magn') - variables.append('divb') - variables.append('curr') - if (eqsys == 'hd' or eqsys == 'mhd') and eos == 'adi' \ - and 'pres' in variables: - variables.append('eint') - if 'dens' in variables and 'pres' in variables: - variables.append('temp') - if (eqsys == 'hd' or eqsys == 'mhd') \ - and 'dens' in variables \ - and 'velx' in variables \ - and 'vely' in variables \ - and 'velz' in variables: - variables.append('ekin') - if (eqsys == 'mhd' or eqsys == 'srmhd') \ - and 'magx' in variables \ - and 'magy' in variables \ - and 'magz' in variables: - variables.append('emag') - if eqsys == 'hd' and 'ekin' in variables and 'eint' in variables: - variables.append('etot') - if eqsys == 'mhd' and 'eint' in variables \ - and 'ekin' in variables \ - and 'emag' in variables: - variables.append('etot') - if (eqsys == 'srhd' or eqsys == 'srmhd') and 'velo' in variables: - variables.append('lore') + # add derived variables if possible + # + variables.append('level') + if 'velx' in variables and 'vely' in variables and 'velz' in variables: + variables.append('velo') + variables.append('divv') + variables.append('vort') + if 'magx' in variables and 'magy' in variables and 'magz' in variables: + variables.append('magn') + variables.append('divb') + variables.append('curr') + if (eqsys == 'hd' or eqsys == 'mhd') and eos == 'adi' \ + and 'pres' in variables: + variables.append('eint') + if 'dens' in variables and 'pres' in variables: + variables.append('temp') + if (eqsys == 'hd' or eqsys == 'mhd') \ + and 'dens' in variables \ + and 'velx' in variables \ + and 'vely' in variables \ + and 'velz' in variables: + variables.append('ekin') + if (eqsys == 'mhd' or eqsys == 'srmhd') \ + and 'magx' in variables \ + and 'magy' in variables \ + and 'magz' in variables: + variables.append('emag') + if eqsys == 'hd' and 'ekin' in variables and 'eint' in variables: + variables.append('etot') + if eqsys == 'mhd' and 'eint' in variables \ + and 'ekin' in variables \ + and 'emag' in variables: + variables.append('etot') + if (eqsys == 'srhd' or eqsys == 'srmhd') and 'velo' in variables: + variables.append('lore') - # check if the requested variable is in the variable list - # - if not vname in variables: - print('The requested variable cannot be extracted from the file datasets!') - return False + # check if the requested variable is in the variable list + # + if not vname in variables: + print('The requested variable cannot be extracted from the file datasets!') + return None - # check if the shrink parameter is correct (block dimensions should be - # divisible by the shrink factor) - # - shrink = max(1, int(shrink)) - if shrink > 1: - if (nn % shrink) != 0: - print('The block dimension should be divisible by the shrink factor!') - return False - sh = shrink - while(sh > 2 and sh % 2 == 0): - sh = int(sh / 2) - if (sh % 2) != 0: - print('The shrink factor should be a power of 2!') - return False + # check if the shrink parameter is correct (block dimensions should be + # divisible by the shrink factor) + # + shrink = max(1, int(shrink)) + if shrink > 1: + if (nn % shrink) != 0: + print('The block dimension should be divisible by the shrink factor!') + return None + sh = shrink + while(sh > 2 and sh % 2 == 0): + sh = int(sh / 2) + if (sh % 2) != 0: + print('The shrink factor should be a power of 2!') + return None - # determine the actual maximum level from the blocks - # - ml = 0 - for n in range(nc): - fname = 'p%06d_%05d.h5' % (nr, n) - lname = op.join(dname, fname) - dblocks = amun_attribute(lname, 'dblocks') - if dblocks > 0: - levels = amun_coordinate(lname, 'levels') - ml = max(ml, levels.max()) + # determine the actual maximum level from the blocks + # + levs = [] + for n in range(nc): + fname = 'p%06d_%05d.h5' % (nr, n) + lname = op.join(dname, fname) + dblocks = amun_attribute(lname, 'dblocks') + if dblocks > 0: + levs = np.append(levs, [amun_coordinate(lname, 'levels')]) + ml = int(levs.max()) - # prepare dimensions of the output array and allocate it - # - dm = np.array(rm[0:ndims] * bm[0:ndims] * 2**(ml - 1) / shrink, \ + # prepare dimensions of the output array and allocate it + # + dm = np.array(rm[0:ndims] * bm[0:ndims] * 2**(ml - 1) / shrink, \ dtype = np.int32) - ret = np.zeros(dm[::-1]) + ret = np.zeros(dm[::-1]) - # iterate over all subdomain files - # - nb = 0 - for n in range(nc): - fname = 'p%06d_%05d.h5' % (nr, n) - lname = op.join(dname, fname) - dblocks = amun_attribute(lname, 'dblocks') - if dblocks > 0: - levels = amun_coordinate(lname, 'levels') - coords = amun_coordinate(lname, 'coords') - dx = amun_coordinate(lname, 'dx') - dy = amun_coordinate(lname, 'dy') - dz = amun_coordinate(lname, 'dz') - f = h5.File(lname, 'r') + # iterate over all subdomain files + # + nb = 0 + for n in range(nc): + fname = 'p%06d_%05d.h5' % (nr, n) + lname = op.join(dname, fname) + dblocks = amun_attribute(lname, 'dblocks') + if dblocks > 0: + levels = amun_coordinate(lname, 'levels') + coords = amun_coordinate(lname, 'coords') + dx = amun_coordinate(lname, 'dx') + dy = amun_coordinate(lname, 'dy') + dz = amun_coordinate(lname, 'dz') + with h5.File(lname, 'r') as f: g = f['variables'] if vname == 'level': dataset = np.zeros(g[variables[0]].shape) @@ -416,8 +416,6 @@ def amun_dataset(fname, vname, shrink = 1, progress = False): else: dataset = g[vname][:,:,:,:] - f.close() - # rescale all blocks to the effective resolution # for l in range(dblocks): @@ -444,13 +442,9 @@ def amun_dataset(fname, vname, shrink = 1, progress = False): % (vname, fname, nb, nl)) sys.stdout.flush() - if (progress): - sys.stdout.write('\n') - sys.stdout.flush() - - except: - print("Dataset '%s' cannot be retrieved from '%s'!" % (vname, fname)) - ret = False + if (progress): + sys.stdout.write('\n') + sys.stdout.flush() return ret From d7f4acdd9c97814c38543b49eafb194b2c44631e Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Fri, 22 Nov 2019 18:12:43 -0300 Subject: [PATCH 24/24] PYTHON: Add setup.py to facilitate package installation. Signed-off-by: Grzegorz Kowal --- python/setup.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 python/setup.py diff --git a/python/setup.py b/python/setup.py new file mode 100644 index 0000000..42d2aa4 --- /dev/null +++ b/python/setup.py @@ -0,0 +1,13 @@ +from setuptools import setup + +setup( + name='amun', + description='Python Interface fo AMUN snapshots', + version='0.1', + author='Grzegorz Kowal', + author_email='grzegorz@amuncode.org', + url='https://www.amuncode.org/', + license='GPLv3', + py_modules=['amun'], + install_requires=['h5py', 'numpy'] + )